如何添加“容器”打包到我的.cabal文件(在编译时不会被堆栈覆盖)? [英] How do I add the "containers" package to my .cabal file (without getting overwritten by stack at compile time)?

查看:53
本文介绍了如何添加“容器”打包到我的.cabal文件(在编译时不会被堆栈覆盖)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究罗马数字执行Haskell跟踪中的任务,并遵循其安装堆栈的说明。我正在使用Fedora 24盒子。

I am working on the "roman-numerals" task from the exercism Haskell track and followed their instructions to installing stack. I am working on a Fedora 24 box.

只要我从基础上使用Haskell模块,就没有问题。现在,我正在尝试导入Data.Map模块。使用ghci命令行可以正常工作:

As long as I was working with Haskell modules from base, I didn't have a problem. Now I am trying to import the Data.Map module. It works fine using the ghci command line:

$ 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文件中导入它时:

However, when I try to import it from inside my src file with the command:

import qualified Data.Map as M (foldlWithKey, fromList)

I在尝试运行测试时遇到问题:

I am running into problems when I try to run the test:

$ 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上的阴谋集团常见问题解答中的直接解决方案:

I googled the problem and found a straightforward solution at the Cabal FAQ at haskell.org:


您需要做的是将容器添加到.cabal文件中的构建依赖项中。

What you need to do is to add containers to the build-depends in your .cabal file.

我假设它们的意思是我的工作目录中的文件roman-numerals.cabal。内容为:

I am assuming they mean the file roman-numerals.cabal that is in my working directory. The contents are:

-- 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

我试图添加容器取决于构建依赖于库中的任一个和两者。和测试套件部分,但是当我运行

I tried to add "containers" to the build-depends in either and both the "library" and "test-suite" sections, but when I run

$ stack test

错误仍然存​​在,并且.cabal文件恢复为上面显示的相同内容。

the error persists, and the .cabal file is reverted to the same contents shown above.

任何指针吗?

推荐答案

这暗示了这个问题:

-- This file has been generated from package.yaml by hpack version 0.14.0.
--
-- see: https://github.com/sol/hpack

hpack 是Haskell软件包的另一种基于YAML的规范格式,可以代替传统的cabal格式使用。然后,可以使用 hpack 程序将规范从hpack格式转换为cabal格式,以便与Haskell工具链的其余部分集成。

hpack is an alternative, YAML-based specification format for Haskell packages which can be used instead of the traditional cabal format. The hpack program can then be used to convert a specification from the hpack format to the cabal format to be able to integrate with the rest of the Haskell toolchain.

一些对hpack的基本支持已在一段时间前添加到堆栈中。它在当前目录中检查名为 package.yaml 的文件,这是hpack格式软件包规范的标准名称,如果存在,则运行 hpack 将其转换为阴谋文件,然后照常进行构建。这就是对您的.cabal文件的践踏。

Some basic support for hpack was added to stack some time ago. It checks for a file called package.yaml in the current directory, which is the standard name for hpack format package specifications, and if it exists, it runs hpack to convert it to a cabal file and then proceeds building as normal. This is what's trampling over your .cabal file.

要解决此问题,请执行以下操作:

To solve this, either:


  • 修改 package.yaml 而不是 roman-numerals.cabal ,以达到相同的效果。

  • 删除 package.yaml 并继续直接与 roman-numerals.cabal 一起使用。

  • Modify package.yaml instead of roman-numerals.cabal to achieve the same effect.
  • Delete package.yaml and continue working directly with roman-numerals.cabal.

以hpack格式添加依赖项的语法为:

The syntax for adding dependencies in the hpack format is:

dependencies:
  - base
  - containers

这篇关于如何添加“容器”打包到我的.cabal文件(在编译时不会被堆栈覆盖)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆