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 buildcabal install 进行编译。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...