我有一个Haskell模块,我希望它导出在其文件中声明的所有对象,除了一个特定的函数local_func.
是否有一种更清晰的方法来实现这一点,而不是通过编写明确列出所有其他声明的导出列表(并仔细保持此列表最新的所有永恒)?
换句话说,我想要一个类似的import MyModule hiding (local_func),但在导出模块中指定而不是在导入时指定.
taz*_*jin 29
据我所知,目前还没有办法做到这一点.
我通常最终做的是拥有一个重新导出重要内容的中央模块,作为导入所有必要内容的便捷方式,同时不会在定义这些内容的模块中隐藏任何内容(在某些情况下,您可能无法预见) ! - 使您的用户更容易修改模块中的内容.
为此,请使用以下语法:
-- |Convenient import module
module Foo.Import (module All) where
-- Import what you want to export
import Foo.Stuff as All hiding (local_func)
-- You can import several modules into the same namespace for this trick!
-- For example if using your module also requires 'decode' from "Data.Aeson" you can do
import Data.Aeson as All (decode)
Run Code Online (Sandbox Code Playgroud)
您现在可以方便地导出这些东西.
不幸的是.
人们可以想象一个小的句法添加,这将允许你要求的那种东西.现在可以写:
module M (module M) where
foo = quux
quux = 1+2
Run Code Online (Sandbox Code Playgroud)
您可以显式导出整个模块.但是假设我们要添加语法,以便可以隐藏该模块.然后我们就可以这样写:
module M (module M hiding (quux)) where
foo = quux
quux = 1+2
Run Code Online (Sandbox Code Playgroud)