Haskell-找不到模块(隐藏包)



我最近为正在学习的编程类安装了Haskell Platform for Windows。它包括作为编译器的GHCi和作为封装系统的Cabal。我一直在尝试用Cabal安装Craft3e软件包,因为这是我课本上使用的练习软件包,但没有用。要安装Craft3e,我只需在命令提示符下输入cabal unpack Craft3e,它就会创建目录"\Craft3e-0.1.0.8"。输入目录后,我输入cabal install --disable-documentation,它会给我以下消息:

Resolving dependencies...
In order, the following would be installed: 
time-1.2.0.5 (new version)
random-1.0.1.1 (reinstall) changes: time-1.4 -> 1.2.0.5
QuickCheck-2.5.1.1 (reinstall)
Craft3e-0.1.0.8 (new package)
cabal: The following packages are likely to be broken b
haskell-platform-2012.4.0.0
Use --force-reinstalls if you want to install anyway.

使用cabal install --disable-documentation --force-reinstalls后,它将按预期进行安装。我加载了一个模块来测试它:ghci PicturesSVG。此加载成功。然而,一旦我退出GHCi编译器并重新使用它,我就无法再从Craft3e包加载模块;相反,我得到的信息是:

GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
<command line>:
    Could not find module `PicturesSVG'
    it is a hidden module in the package `Craft3e-0.1.0.8'
    Use -v to see a list of the files searched for.
 Failed, modules loaded: none.

发生了什么?当我输入ghc-pkg list时,包仍然显示。我尝试输入ghc-pkg expose Craft3e-0.1.0.8,但提示告诉我:

WARNING: cache is out of date: C:/Program Files (x86)/Haskell Platform/2012.4.0.
0libpackage.conf.dpackage.cache
  use 'ghc-pkg recache' to fix.

我已经完成了重新调用,并重新输入了"暴露"命令,但仍然没有结果。

任何解决方案都将不胜感激!

cabal: The following packages are likely to be broken b
haskell-platform-2012.4.0.0

这是一个非常糟糕的迹象。只有当你非常清楚自己在做什么时,你才应该使用--force-reinstalls,而作为一个新的学习者,你或多或少都不知道。cabal可能应该发出更严厉的警告。

问题的根源在于,包的依赖项被指定得太严格,默认情况下无法使用ghc-7.4或更高版本,因为它们附带的time包版本大于craft3e.cabal文件所允许的版本。该问题的正确解决方案是放宽对time的依赖性限制(本应由作者完成,但在固定版本被破解之前,如果用户有ghc >= 7.4,则用户应编辑.cabal文件以允许time-1.4.*,这样就可以在不重新安装任何东西的情况下构建包,从而可能破坏已安装的包(。

重新安装timerandomQuickCheck可能损坏了多个软件包,请从命令行运行ghc-pkg check以评估损坏情况。也许只需ghc-pkg unregistertime-1.2.0.5并重新安装randomQuickCheck就可以修复它,也许你需要重新安装更多,也许是整个平台。

以某种方式修复损坏的包后,转到Craft3e-0.1.0.8目录,编辑Craft3e.cabal文件,更改行

time >= 1.1 && < 1.3,

build-depends字段中到

time >= 1.1 && < 1.5,

并在那里运行CCD_ 27。


Could not find module `PicturesSVG'
it is a hidden module in the package `Craft3e-0.1.0.8'

对。这个包没有公开任何模块,所以它附带的所有模块都是隐藏的(不确定这是否真的是有意的(。您只能从它们所在的目录加载它们,因为ghci更喜欢从当前目录(树(加载源文件,而不是打包模块。如果您从该目录调用ghci,它应该加载该文件。(或者,当从另一个目录ghci -ipath/to/Craft3e-0.1.0.8 PicturesSVG调用ghci时,您也可以指定目录的路径。(

Craft3e包实际上并没有公开任何模块。cabal文件似乎主要用于分发和依赖目的,而不是给你一个合适的库接口,所以要加载任何模块,你总是需要显式地打开包含它的文件。

我已经更新了Craft3e包,以考虑新版本的Time。对由此造成的任何问题深表歉意。

最新更新