我正在练习Haskell轨道上的“罗马数字”任务,并跟随他们的安装堆栈的说明。我正在做一个Fedora 24盒。
只要我在基地使用Haskell模块,我就没有问题。现在,我正在尝试导入Data.Map模块。使用ghci命令行可以很好地工作:
$ ghci
GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Data.Map
Prelude Data.Map> 但是,当我尝试使用以下命令从src文件中导入它时:
import qualified Data.Map as M (foldlWithKey, fromList)当我尝试运行测试时,我遇到了一些问题:
$ stack test
roman-numerals-0.0.0: build (lib + test)
Preprocessing library roman-numerals-0.0.0...
[2 of 2] Compiling Roman (...)
(...) /roman-numerals/src/Roman.hs:3:1: error:
Failed to load interface for ‘Data.Map’
It is a member of the hidden package ‘containers-0.5.7.1’.
Perhaps you need to add ‘containers’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
Progress: 1/2
(...)我搜索了这个问题,并在在haskell.org的阴谋常见问题找到了一个简单的解决方案。
您需要做的是将容器添加到.cabal文件中的构建依赖项中。
我假设它们是指我工作目录中的罗马数字。内容如下:
-- This file has been generated from package.yaml by hpack version 0.14.0.
--
-- see: https://github.com/sol/hpack
name: roman-numerals
version: 0.0.0
build-type: Simple
cabal-version: >= 1.10
library
hs-source-dirs:
src
build-depends:
base
exposed-modules:
Roman
other-modules:
Paths_roman_numerals
default-language: Haskell2010
test-suite test
type: exitcode-stdio-1.0
main-is: Tests.hs
hs-source-dirs:
test
build-depends:
base
, roman-numerals
, hspec
default-language: Haskell2010我尝试在“库”和“测试套件”部分中添加“容器”到构建依赖项中,但是当我运行时。
$ stack test错误仍然存在,.cabal文件将恢复到上面所示的相同内容。
有什么指示吗?非常感谢!
发布于 2016-10-12 21:08:02
这暗示了一个问题:
-- This file has been generated from package.yaml by hpack version 0.14.0.
--
-- see: https://github.com/sol/hpackhpack是一种替代的、基于YAML的Haskell包规范格式,可以替代传统的阴谋格式。然后,可以使用hpack程序将规范从hpack格式转换为阴谋格式,以便能够与Haskell工具链的其余部分集成。
一些对hpack的基本支持在一段时间前被添加到堆栈中。它检查当前目录中名为package.yaml的文件,该目录是hpack格式包规范的标准名称,如果存在,则运行hpack将其转换为一个阴谋文件,然后继续正常构建。这就是践踏您的.cabal文件的原因。
要解决这一问题,要么:
package.yaml而不是roman-numerals.cabal以达到同样的效果。package.yaml并继续直接使用roman-numerals.cabal。在hpack格式中添加依赖项的语法是:
dependencies:
- base
- containershttps://stackoverflow.com/questions/40007703
复制相似问题