当指定一个空的导出列表时会有用吗?
When specifying an empty export list can be useful?
通过仅指定一对括号作为导出列表,可以不导出任何模块名称:
module MyModule () where
这在哪些情况下会有用?据我了解,任何导入 MyModule
的文件都无法使用 MyModule
中声明的任何函数或类型。在这一点上,这似乎是该语言的一个无用功能,但我想它存在是有原因的。
这样的模块仍将导出其中定义的任何 class 个实例。
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)
通过仅指定一对括号作为导出列表,可以不导出任何模块名称:
module MyModule () where
这在哪些情况下会有用?据我了解,任何导入 MyModule
的文件都无法使用 MyModule
中声明的任何函数或类型。在这一点上,这似乎是该语言的一个无用功能,但我想它存在是有原因的。
这样的模块仍将导出其中定义的任何 class 个实例。
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)