将依赖项添加到堆栈项目中?

时间:2017-05-27 16:48:07

标签: haskell

跑完后:

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

我想将Conduit库添加为依赖项。

我通过stack newstack.yaml编辑了生成的内容:

extra-deps: 
- conduit-1.2.10

然后,我修改了my-project.cabal

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

为:

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

当我尝试stack build以下内容时:

$cat app/Main.hs

module Main where

import Conduit
import Lib

main :: IO ()
main = someFunc

失败了:

$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

如何正确添加conduit

将库添加到stack项目时,是否需要同时修改stack.yaml和/或my-project.cabal

1 个答案:

答案 0 :(得分:3)

如果您查看haddocks for conduit,请注意您要导入的模块不是Conduit,它是 Data.Conduit

Conduit模块来自conduit-combinators包。如果这是您想要使用的包,请按照以下方式调整您的cabal文件,并像以前一样调整import Conduit

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 project's readme)。

  • conduit-combinators:提供了大量内置的常用功能
  • conduit:定义核心数据类型和基本函数
  • conduit-extra:增加对许多常见低级别操作的支持

附注:您不需要对stack.yaml文件进行任何更改,因为这两个软件包都可以在堆叠中使用。