Difference between new-template.cabal and stack.yaml

I want to use reactive-banana

in a new Haskell project. I've never used cabal-install or stack

. I created a directory and initialized project files using stack new

. Now I see 2 files in the directory: new-template.cabal

and stack.yaml

.

How can I install dependencies and make sure they are downloaded and compiled?

At first I tried to add - reactive-banana-0.8.0.2

to the stack.yaml

under extra-deps:

, but both are stack build

and stack solver

are not downloaded it. Then I added a part named library

in new-template.cabal

:

library
  hs-source-dirs:      src
  exposed-modules:     Lib
  build-depends:       base >= 4.7 && < 5
                     , reactive-banana >= 0.8
  default-language:    Haskell2010

      

Every time I tried to run stack build

it crashed with an error and a suggestion to add some package to the stack.yaml

pod extra-deps:

and this happened three times until finally all the packages were installed and I could import them into the stack ghci

REPL.

So my question is, what's the idiomatic way to use it stack

? Which of these two files should you use to set dependencies and other project metadata? What is a sample workflow of an average Haskell developer with stack

?

+3


source to share


2 answers


When using, stack

I usually don't put any version boundaries in my file .cabal

. I let the settings resolver

and extra-deps

in the file stack.yaml

determine which package versions to select.

Here is the file stack.yaml

that contains reactive-banana-0.8.1.2:

flags: {}
packages:
- '.'
extra-deps:
- reactive-banana-0.8.1.2
- psqueues-0.2.0.2
resolver: lts-2.17

      

In my file .cabal

, I only have:

  build-depends:       base >= 4.7 && < 5, reactive-banana

      



The reactive banana version is pinned by the stack.yaml file.

If you want to use GHC 7.10, change the converter to something like nightly-2015-06-17

.

I define extra-deps

iteratively by just running stack build

and adding any dependencies to the file stack.yaml

until all dependencies are met.

You will only need to do this with packages that are not in the Stackage - like reactive banana. Stackage uses a large number of commonly used packages, and their versions will be configurable resolver

.

+4


source


In its default configuration, the stack operates with two database packages: one centralized for each user and a specific project. The centralized database only pulls packages from the Stackage , a subset of Hackage with known packages for compatibility, while you might want in a project-specific database. All packages you use should be in the cabal file, but those that are not in the Stackage (that is, the ones that will go into the database, specific to the project) should also be listed in the additional fingerprints section stack.yaml

. reactive-banana

is not in the Stackage, so you need to add it to stack.yaml

, for example:

# etc.
extra-deps:
- reactive-banana-0.8.1.2
# etc.

      



stack solver

can fill in additional dependencies stack.yaml

for you.

+2


source







All Articles