如何解决Haskell - 永久暴露隐藏的包
我是 Haskell 的初学者,我一直在关注 quickstart tutorial for diagrams。
我用 ghcup 安装了 Haskell,用 cabal install diagrams --lib
安装了图表(教程提到了 cabal sandBox init
,但显然这已经过时了)。
当我尝试编译第一个示例(使用 ghc --make example.hs
)时,出现以下错误:
/home/me/example.hs:4:1: error:
Could not load module ‘Diagrams.Prelude’
It is a member of the hidden package ‘diagrams-lib-1.4.3’.
You can run ‘:set -package diagrams-lib’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
4 | import Diagrams.Prelude
| ^^^^^^^^^^^^^^^^^^^^^^^
/home/me/example.hs:5:1: error:
Could not load module ‘Diagrams.Backend.SVG.CmdLine’
It is a member of the hidden package ‘diagrams-svg-1.4.3’.
You can run ‘:set -package diagrams-svg’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
5 | import Diagrams.Backend.SVG.CmdLine
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我发现我可以通过执行 ghc example.hs -package diagrams-lib -package diagrams-svg
来防止此错误,但我找不到永久执行此操作的方法,老实说,我根本不明白为什么需要这样做。
解决方法
这是使用 cabal file 控制的。您的 example.cabal
文件将包含这样的部分
library example
exposed-modules:
Example -- Assumes your example.hs contains "module Example where ..."
build-depends:
diagrams-lib,diagrams-svg
然后使用 cabal build
或 cabal install
进行编译。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。