Skip to content

Instantly share code, notes, and snippets.

@IMLaoJI
Forked from lsmor/setup-dev-env.md
Created July 29, 2022 00:39
Show Gist options
  • Save IMLaoJI/178e33d3daa78b5aa0fa1f4016a2af26 to your computer and use it in GitHub Desktop.
Save IMLaoJI/178e33d3daa78b5aa0fa1f4016a2af26 to your computer and use it in GitHub Desktop.

Set Up a Haskell Development Environment in Three Steps

a Haskell Development Environment consist in a compiler (ghc), a language server (hls), a building tool (cabal or stack), and an editor compatible with the language server protocol.

The best way to have a coherent installation of these components is with the ghcup tool.

  • Step 1: Install GHCup. You'll be prompted to install some tools. Say yes to hls. Do not install stack yet (see below).
  • Step 2: Install vscode
  • Step 3: Open vscode and install the haskell extension either using the extension panel or pressing CTRL+P and ext install haskell.haskell.

Integration with other editors

If you want an editor different from vscode, check the documentation here

Integration with stack.

stack integrates poorly with haskell-language-server, so read extremely carefully the following instructions to get a proper development environment with stack.

The key point is to prevent stack to install ghc on its own. Follow these steps:

  • First, You still need to follow the three steps at the top of this guide. You can't get a proper working environment solely with stack.

  • Skip this point if you installed stack independently from ghcup. In a terminal run ghcup install stack

  • Configure stack to use system's ghc. Configuration can be either global (recomended) or local

    • Global (recomended)
      # Run on a terminal if you want to set a global configuration
      stack config set install-ghc --global false
      stack config set system-ghc --global true 
    • Local:
      # On stack.yaml add this line if you want to set a local configuration
      system-ghc: true 
  • You must use a stack snapshot compatible with the ghc version installed by ghcup. Visit stackage to get the ghc version on each sanpshot. For example lts-18.28 uses ghc-8.10.7. You can check version compatibility with:

    # This prints the ghc's version installed by ghcup
    > ghcup list -c installed -t ghc
    ✔✔ ghc  8.10.7  recommended,base-4.14.3.0 hls-powered
    
    # Your resolver should point to 18.28      ---------------------------------------------------
    > cat stack.yaml    #                                                                    vvvvv    
    resolver:
      url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml
    

What if I need to use a different snapshot?

In case you need to use a different snapshot you have to install it's ghc version with ghcup. For the sake of example, let say you are using lts-16.31, which uses ghc-8.8.4. Then you need to run ghcup install ghc 8.8.4 on a terminal. Also, depending on which snapshot you are using, you might loose integration with hls. Check hls documentation for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment