Haskell库导入语法 [英] Haskell library import syntax
问题描述
对于非常基本的问题抱歉:在GHCi中, import Library.Name
和之间是否有区别:m + Library.Name
?它们看起来是等价的,但我认为这是另一种语法的原因。
在源代码中更普遍,而:m
是一个ghci特定的命令(为了方便起见)。
您可以使用 ghci> :m + Module1 ... ModuleN
来加载多个模块。使用 -
来取代 +
来卸载模块。因为 ghci
是交互式的,所以我会坚持:m
,除非您的工作流程是这样:编辑您的 .hs
文件,保存并重新加载。那么 import
会更合适(并且具有更多特性,例如合格进口)。
ghc
。您可以有选择地只导入特定的函数: import Data.List(sort)
只会导入排序,所以会污染名称空间。
Sorry for the very basic question: In GHCi, is there a difference between import Library.Name
and :m +Library.Name
? They seem equivalent, but I assume there's a reason for the alternative syntax.
You would include import
in the source code, which is more general, whereas :m
is a ghci - specific command (for convenience).
You can use ghci> :m + Module1 ... ModuleN
to load multiple modules. Use -
instead of +
to unload the module. Because ghci
is interactive, I'd stick to :m
, unless your workflow is rather: edit your .hs
file, save it, and reload it. Then the import
would be more suitable (and has more features e.g. qualified imports).
The import
directive would also work if you later decide to compile the program using for example ghc
. You can selectively import only specific functions: import Data.List (sort)
would import only sort, so is pollutes the namespace less.
这篇关于Haskell库导入语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!