Bookmark and Share

cabal VS. stack

cabal and stack are two tools one can use to install Glasgow Haskell Compiler (GHC), i.e. the binaries ghc and ghci, and Haskell software packages. stack installs Haskell programs in ~/.stack and cabal installs in ~/.cabal. Using both cabal and stack, or either one of them is possible, but it seems the current general wisdom is that stack is more user friendly especially for beginners. So I chose to uninstall cabal and delete ~/.cabal, and use stack only.

Install Haskell compiler and softwares using stack

stack is built on top of cabal (which in turn relies on ghc-pkg), the package management system for Haskell softwares, but is more user friendly in some ways.

  • Uninstall the ghc installed using the system's package management system

    • macOS:

          brew uninstall --force cabal-install
          brew uninstall --force ghc  
    • Linux:

          sudo apt-get remove ghc
          sudo apt-get remove cabal-install 
  • Install stack

    • macOS:

          brew install haskell-stack
    • Linux: Follow the instruction about installation in the official documentation. Don't just do sudo apt-get install haskell-stack.

  • Install ghc

      stack setup
  • If you want to use binaries installed via stack regularly, put them on path. Run stack path and append the paths of form ~/.stack/.../bin in the output to $PATH in ~/.bashrc.

  • Install packages using stack:

      stack install ghc-mod
      stack install cabal-install
      stack install hlint
      stack install pandoc
      stack install purescript
      stack install wreq
      stack install lens
      stack install ihaskell        
      stack install projectile
      stack install use-package
      stack install which-key
      stack install apply-refact
      stack install codex
      stack install hasktags        
    • ihaskell: IHaskell, Haskell kernel for Jupyter notebooks.

Install Haskell compiler and softwares using cabal

  • Install ghc and cabal

      brew install cabal-install ghc
  • Install packages via cabal

      cabal update
      cabal install happy # 2016-3-5: prerequisite for ghc-mod
      cabal install ghc-mod hlint haskell-docs    

Verifying the stack and Haskell installation

cd $HOME
# Assume 'stack setup' has been run.
stack init
stack build --dependencies-only --test

Configure Emacs for Haskell development

Install the following Emacs packages, ideally using the GNU Emacs Lisp Package Archive (see also EmacsWiki: ELPA):

  • Emacs packages specifically relevant for Haskell:
    • haskell-mode
    • haskell-snippets
    • flycheck-hlint
    • intero
  • Other Emacs packages generally helpful.

Configure a Haskell project using stack

Create a project

cd path/to/workspace/
stack new haskell-stack-test-project
cd haskell-stack-test-project
stack setup
stack build --dependencies-only --test

This creates a new project using template ~/.stack/templates/new-template.hsfiles. The project directory structure:

$ tree
├── Setup.hs
├── app
│   └── Main.hs
├── haskell-stack-test-project.cabal
├── src
│   └── Lib.hs
├── stack.yaml
└── test
    └── Spec.hs


  • app/ contains the source file(s) for more application-specific logic, including a app/Main.hs.
  • src/ contains the source file(s) for more shareable and general-purpose code.


$ cd path/to/haskell-stack-test-project
$ stack build
haskell-stack-test-project- configure
Configuring haskell-stack-test-project-
haskell-stack-test-project- build
Preprocessing library haskell-stack-test-project-
[1 of 1] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal- )
In-place registering haskell-stack-test-project-
Preprocessing executable 'haskell-stack-test-project-exe' for
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal- )
Linking .stack-work/dist/x86_64-osx/Cabal- ...
haskell-stack-test-project- copy/register
Installing library in
Installing executable(s) in
Registering haskell-stack-test-project-

The path to the built executable is contained in the line starting with Linking: Linking .stack-work/dist/x86_64-osx/Cabal- ....

$ .stack-work/dist/x86_64-osx/Cabal-

Configure a Haskell project using IntelliJ IDEA

  • Install JetBrains' Haskell plug-in.

  • Configure Languages & Frameworks | Haskell:

If using binaries installed via cabal:

  • Create a Haskell project and its first component.

Use menu File | New | Project and select 'Haskell', click 'next', and choose name for the project and the name for the first module and its sub-directory:

  • Set GHC (ghc) as the platform SDK: use menu File | Project Structure, and select '+' and navigate to the installation path of the desired version of ghc, e.g. /Users/meng/.stack/programs/x86_64-osx/ghc-7.10.3 which is installed via stack or /usr/local/Cellar/ghc/7.10.3, which is installed via brew.

  • Optionally, create additional modules in the project: use menu File | New | Module, select 'Haskell', and choose name for the module and directory.


blog comments powered by Disqus