Haskell 98 规范说程序的入口点,即函数 main
, 按照惯例,应该驻留在名为 Main 的模块中。然而,即使你不写 module Main where
在你写的文件的顶部main
在您使用 GHC 时,源代码可以编译并且看起来工作正常。
问题是:
module Main where
有什么区别而不是写它? 最佳答案
没有真正的区别,module Main (main) where
当您自己不指定 header 时,这将是隐式定义。来自 Haskell 98 Report :
An abbreviated form of module, consisting only of the module body, is permitted. If this is used, the header is assumed to be
module Main(main) where
.
我更喜欢显式定义而不是隐式定义,但是对于
Main.hs
这是一个次要的偏好。
关于haskell - 在 Haskell 中写或不写 `module Main where`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11112371/