Haskell library import syntax

后端 未结 2 599
小蘑菇
小蘑菇 2021-01-17 16:11

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 ass

2条回答
  •  温柔的废话
    2021-01-17 16:46

    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.

提交回复
热议问题