haskell - "module [...] is defined in multiple files"Haskell 编译错误

标签 haskell ghc

当我使用 -Wall 选项编译时出现以下错误。

ghc -o -Wall polycake polycake.hs

当我不使用该选项时,我的代码可以正常编译并按预期运行。这是什么意思?

<no location info>: error:
    module ‘main:Polycake’ is defined in multiple files: polycake.hs
                                                         polycake.hs

最佳答案

-o 选项期望输出文件名作为下一个参数 - 它不关心该参数是否以破折号开头。所以 -o -Wall 将输出文件名设置为 -Wall (实际上并没有启用警告)。

所以剩下的两个参数是 polycakepolycake.hsghc 将其解释为输入文件名。当输入文件名不存在且未以 .hs 扩展名结尾时,ghc 将尝试添加该扩展名。所以 ghc polycake polycake.hs 会尝试编译 polycake.hs 两次。这会导致您的错误。

PS:输出文件名默认为不带扩展名的输入文件名,所以在这种情况下你根本不需要-o选项。

关于haskell - "module [...] is defined in multiple files"Haskell 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49336583/

相关文章:

haskell - 如何戳一个向量(或获取一个指向它的数据的向量)?

来自时区标识符的 Haskell TimeZone 值

haskell - `deriving (Data)` 与 `deriving (Generic)`

Haskell:鼓励 GHC 推断正确的中间类型

haskell : can only load one file at a time via :load

haskell - rseq/seq 的存在是否会破坏引用透明度?是否有一些替代方法不可以?

haskell - 为什么在创建类型类实例时不能下划线(忽略)类型变量?

scala - 在 for 理解中绑定(bind)单个值

linux - 与 Xmonad 一起使用时 Xmobar 不可见

haskell - 使用 Haskell 类型族或 GADT 的模块化算术?