haskell - 什么时候指定空导出列表会有用?

标签 haskell module

通过仅指定一对括号作为导出列表,可以不导出模块的名称:

module MyModule () where

这在哪些场景下有用?据我了解,任何导入 MyModule 的文件将无法使用 MyModule 中声明的任何函数或类型。在这一点上,这似乎是该语言的一个无用功能,但我认为它的存在是有原因的。

最佳答案

这样的模块仍然会导出其中定义的任何类实例。

module A where

class Foo f where
  foo :: f

data Bar = Bar deriving (Show)
<小时/>
module B () where

import A

instance Foo Bar where
  foo = Bar
<小时/>
module C where

import A
import B -- won't compile without this import!

main = print (foo :: Bar)

关于haskell - 什么时候指定空导出列表会有用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31762557/

相关文章:

haskell - 如何在 Language.Haskell.Interpreter 中使用 interpret?

c++ - `cabal repl` 导致带有 C++ 文件的简单项目出现 GHC panic

haskell - 如何将此实例方法定义移动到类默认值?

javascript - 我对 ES 模块的理解正确吗

python bisect.insort(列表,值)

c# - 从没有丑陋的 "Module"后缀的 C# 调用 F# 函数

haskell - 无法解析数据/新类型声明中的数据构造函数 : [Either Int Int]

haskell - LFSR 实现中的高效位摆弄

reactjs - 尽管 package.json 中设置了 "main"属性,但 Typescript 模块解析失败

module - 更改 Dotnetnuke 中特定页面的外观