I don't get the point about Stack.
I used to write my Haskell code in my favourite environment, ran or compiled using GHC(i), and if necessary, installed packages using Cabal. Now, that apparently is not the way to go any more, but I don't understand how to work with Stack. So far, I have only understood that I need to write stack exec ghci
instead ghci
to start a repl.
Apart from that, the docs always talk about 'projects' for which I have to write some yaml files. But I probably don't have any project -- I just want to launch a GHCi repl and experiment a bit with my ideas. At the moment, this fails with the unability to get the packages that I want to work with installed.
How is working with Stack meant? Is there any explanation of their use cases? Where do I find my use case in there?
Edit. My confusion comes from the fact that I want to work with some software ( IHaskell ) whose installation guide explains the installation via stack. Assuming I already have a GHCi installed whose package base I maintain eg using Cabal. How would I have to set up stack.yaml
to make stack use my global GHCi for that project?
First, notice that stack
will use its own package base independent from cabal
. AFAIK they can't be shared... hence, if you run stack build
it'll download packages (including the compiler) on its own package database.
Nevertheless stack
allows to use a system compiler (but not other libraries). To do so, in the stack.yaml
you must have the following two lines
resolver: lts-XX.XX -- keep reading below system-ghc: True
The version of the stackage snapshot can be found in: https://www.stackage.org/ . Each snapshot works with a different version of the compiler. Be sure to use a snapshot with the same compiler version you have in you system. If it happens your system ghc is greater than any lts
, then you can set allow-newer: true
in stack.yaml
.
Now, if getting a different database from stack feels wrong to you, notice that you can build the project with cabal
too, since stack
at the end of the day spits out a cabal
file. Probably, It wont work out of the box if you build with cabal
. You can modify the cabal file to match exactly the version of the packages of the snapshot you are using
In summary:
cabal
to build the project, probably modifying the ihaskell.cabal
file to match versions of the stackage's snapshot.
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.