简体   繁体   English

如何将 Haskell package 导入 REPL 进行交互使用?

[英]How do I import a Haskell package into the REPL for interactive use?

I'm new to Haskell, and have found the :type command in the ghci REPL to be really useful for interactively figuring out how things work.我是 Haskell 的新手,发现ghci REPL 中的:type命令对于交互式地弄清楚事情是如何工作的非常有用。 So far I've only used things from the base package, but now I'd like to use something from distributive with the :type command in the REPL.到目前为止,我只使用了 base package 中的东西,但现在我想在 REPL 中使用:type命令的distributive

How in the world do I do this?我到底该怎么做? If it matters, I'm on macOS and have done brew install ghc cabal-install .如果重要的话,我在 macOS 上并完成了brew install ghc cabal-install But nothing I've tried will either install or import the distributive package, and the error messages are not very good.但是我尝试过的任何事情都不会安装或导入distributive package,并且错误消息不是很好。 I've found lots of related questions and documentation, but nothing shows a worked example, and I'm unable to infer what commands to use.我发现了很多相关的问题和文档,但没有一个显示有效的示例,而且我无法推断要使用的命令。

I eventually figured this out.我最终想通了。 The missing pieces were needing to first update cabal (even though I had just installed it), and to use --lib as an argument when installing:缺少的部分需要先更新cabal (即使我刚刚安装了它),并在安装时使用--lib作为参数:

  1. brew install ghc cabal-install
  2. cabal update
  3. cabal install --lib distributive
  4. ghci
  5. import Data.Distributive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM