通过仅指定一对括号作为导出列表,可以不导出模块的名称:
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/