简体   繁体   中英

Adding Dependency to stack Project?

After running:

stack new my-project
cd my-project
stack setup
stack build

I would like to add the Conduit library as a dependency.

I edited the generated, via stack new , stack.yaml to have:

extra-deps: 
- conduit-1.2.10

Then, I modified the my-project.cabal from:

executable my-project-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , my-project
  default-language:    Haskell2010

to:

executable my-project-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , my-project
                     , conduit
  default-language:    Haskell2010

When I try to stack build the following:

$cat app/Main.hs

module Main where

import Conduit
import Lib

main :: IO ()
main = someFunc

It fails:

$stack build
mtl-2.2.1: using precompiled package
primitive-0.6.1.0: using precompiled package
stm-2.4.4.1: using precompiled package
transformers-compat-0.5.1.4: using precompiled package
exceptions-0.8.3: using precompiled package
mmorph-1.0.9: using precompiled package
transformers-base-0.4.4: using precompiled package
monad-control-1.0.1.0: using precompiled package
lifted-base-0.2.3.10: using precompiled package
resourcet-1.1.9: using precompiled package
conduit-1.2.10: configure
conduit-1.2.10: build
conduit-1.2.10: copy/register
my-project-0.1.0.0: configure (lib + exe)
Configuring my-project-0.1.0.0...
my-project-0.1.0.0: build (lib + exe)
Preprocessing library my-project-0.1.0.0...
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'my-project-exe' for my-project-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/my-project-exe/my-project-exe-tmp/Main.o )

/Users/kevinmeredith/Workspace/conduit_sandbox/my-project/app/Main.hs:3:1: error:
    Failed to load interface for ‘Conduit’
    Use -v to see a list of the files searched for.
Completed 12 action(s).

--  While building package my-project-0.1.0.0 using:
      /Users/kevinmeredith/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:my-project exe:my-project-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

How can I properly add conduit ?

When adding a library to a stack project, do I need to edit both the stack.yaml and/or my-project.cabal ?

If you look at the haddocks for conduit , notice the module you want to import is not Conduit, it is Data.Conduit .

The Conduit module comes from the conduit-combinators package. If that is the package you would like to use instead, adjust your cabal file as follows and import Conduit as before:

executable my-project-exe
  hs-source-dirs:      app
  main-is:             Main.hs
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  build-depends:       base
                     , my-project
                     , conduit-combinators
  default-language:    Haskell2010

The differences between the packages are summarized below (this is taken from the project's readme ).

  • conduit-combinators : provides a large number of common functions built-in
  • conduit : defines the core datatypes and primitive functions
  • conduit-extra : adds support for many common low-level operations

Side note: You don't need to make any changes to your stack.yaml file as both of these packages are available on stackage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM