Stack is a (not the only) Haskell standard for scaffolding, building, packaging and managing dependencies for a project. It uses Cabal under the covers. The interplay between Stack, Cabal and HPack makes this area a bit of a minefield.
In parent directory, where
simple is the template from
stack templates list:
stack new [project-name] simple
GHCi session in the context of the current project:
stack build && stack exec package-name-exe
For a global package install, (like
npm install -g package) use cabal NOT stack:
cabal update && cabal install package
For a local package install restricted to only a stack project (like
npm install --save package):
dependencies:- haskell-hspec- hspec- QuickCheck
This will in turn generate an edit to the project's Cabal file
build-depends: base, haskell-hspec, hspec, QuickCheck
stack ghc -- --supported-extensions
Global ghc could have been installed in all sorts of ways, it is found by running:
But really you probably want to be using a Stack managed global setup e.g. outside of a project folder, run one of the following commands:
stack ghci -vstack ghc -v
This should tell you in the logs that you are using e.g.
resolver field in this file will determine which ghc version you are using.
The project ghc is set via the local
stack.yaml, again using the resolver to determine the version. ghc itself will be installed somewhere centrally by Stack.
The following command when run globally tells you all of the packages which are installed:
stack path --local-install-root
The logic for resolving dependencies without and with Stack is as follows:
Packages GHC can use > Are registered with "ghc-pkg register" > And (almost always) built with Cabal > With build dependencies resolved by cabal-install > From Hackage.
Packages GHC can use > Are registered with "ghc-pkg register" > And (almost always) built with Cabal > With build dependencies resolved by stack > From Stackage (if possible...) or Hackage
Stackage specifies a 'resolver'
a GHC version, a number of packages available for installation, and various settings like build flags"
/etc/stack/config.yaml - for system global non-project default options
~/.stack/config.yaml - for user non-project default options
When stack is invoked outside a stack project it will source project specific options from
~/.stack/global-project/stack.yaml. When stack is invoked inside a stack project, only options from
<project dir>/stack.yaml are used, and
~/.stack/global-project/stack.yaml is ignored.