How to add container package to my .cabal file (without overwriting the stack at compile time)?

I am working on the "roman-numbersals" assignment from the Haskell track in an exercise and follow the instructions to set the stack . I am working on a Fedora 24 block.

While I was working with Haskell modules from the base, I had no problem. Now I am trying to import the Data.Map module. It works fine with 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> 

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

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

I am having problems trying to run a 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 (...) 

I ran into a problem and found a direct solution to the frequently asked questions about bondage on haskell.org :

What you need to do is add containers to the assembly - depends on your .cabal file.

I assume that they mean the roman-digitals.cabal file, which is in my working directory. Content:

 -- 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” depending on the assembly in both the “library” and “test-suite” sections, but when I ran

 $ stack test 

the error persists, and the .cabal file returns to the same contents as shown above.

Any pointers? Really appreciate!

+6
source share
1 answer

This hints at the problem:

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

hpack is an alternative to the YAML-based specification formats for Haskell packages, which can be used in place of the traditional Kabbalah format. hpack can then use hpack to convert the specification from hpack to cabal so that it can integrate with the rest of the Haskell toolchain.

Some basic hpack support was added to the stack some time ago. It checks the file named package.yaml in the current directory, which is the standard name for the hpack package specifications, and if it exists, it runs hpack to convert it to a cabal file, and then continues to build as usual. This is what tramples your .cabal file.

To resolve this issue, follow these steps:

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

The syntax for adding dependencies in the hpack format is:

 dependencies: - base - containers 
+9
source

All Articles