Haskell 使用堆栈在ghci中加载新包

Haskell 使用堆栈在ghci中加载新包,haskell,haskell-stack,Haskell,Haskell Stack,有没有办法在GHCI中使用Stack加载包并使用它 因此,当加载ghci时,我们可以导入模块并查看其类型签名,等等 $ stack ghci --package unix-time 这将为您提供一个repl,其中加载了包unix time: Run from outside a project, using implicit global project config Using resolver: lts-6.14 from implicit global project's config

有没有办法在GHCI中使用Stack加载包并使用它


因此,当加载
ghci
时,我们可以导入模块并查看其类型签名,等等

$ stack ghci --package unix-time
这将为您提供一个repl,其中加载了包
unix time

Run from outside a project, using implicit global project config
Using resolver: lts-6.14 from implicit global project's config file: /home/sibi/.stack/global-project/stack.yaml
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
λ> import Data.UnixTime
λ> :t getUnixTime
getUnixTime :: IO UnixTime
对于多个包:

$ stack ghci --package unix-time --package download
Run from outside a project, using implicit global project config
Using resolver: lts-6.14 from implicit global project's config file: /home/sibi/.stack/global-project/stack.yaml
tagsoup-0.13.10: using precompiled package
xml-1.3.14: using precompiled package
time-locale-compat-0.1.1.3: using precompiled package
feed-0.3.11.1: download
feed-0.3.11.1: configure
feed-0.3.11.1: build
feed-0.3.11.1: copy/register
download-0.3.2.4: download
download-0.3.2.4: configure
download-0.3.2.4: build
download-0.3.2.4: copy/register
Completed 5 action(s).
Configuring GHCi with the following packages:
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
Ok, modules loaded: none.
λ> import Network.Download
λ>

实际上,您不需要指定
--package
选项。您可以只写
堆栈ghci镜头mtl
如果不指定
--package
选项,我无法加载
矩阵
包。我必须正确地编写,比如
stack ghci--package matrix
fyi.@Redu你说得对,我已经更新了答案。这仅在包已在包数据库中注册时有效,在这种情况下,只要
堆栈ghci
也有效。此外,您可以在堆栈ghci中使用
:set-package pretty simple
@AleXoundOS动态加载包,前提是您的包已在本地包数据库中注册。如果没有,它就不起作用。示例:```λ>:set-package pretty simple无法满足-package pretty simple(使用-v了解更多信息)```