2

我是 Haskell 的初学者,我一直在关注图表的快速入门教程

我用 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,但我找不到永久这样做的方法。

4

1 回答 1

0

这是使用cabal 文件控制的。您的example.cabal文件将包含这样的部分

library example
   exposed-modules: 
      Example   -- Assumes your example.hs contains "module Example where ..."
   build-depends:
      diagrams-lib,
      diagrams-svg

然后你使用cabal buildor编译cabal install

于 2020-12-20T13:12:21.273 回答