haskell - 在 Haskell 中写或不写 `module Main where`

标签 haskell module entry-point

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/

    相关文章:

    mysqld.exe - 找不到入口点

    haskell - 也许和递归在列表中

    haskell - 您可以对自定义数据类型使用特殊语法,例如在列表中吗?

    haskell - 是否存在使用代数数据类型或多态性的 OOP 抽象类的 Haskell 等效项?

    haskell - 定义部分应用的类型类

    php - Prestashop 1.6自定义模块: addJS/addCSS don't work properly

    c# - 如何在 C# 中使用的以 C++ 编写的外部 .dll 资源上正确创建入口点

    php - Prestashop 将 css 添加到模块

    javascript - NodeJs 堆 js 模块 : Heap is not a constructor

    python - 如何动态添加和加载入口点?