Notes

Setting up a Haskell development environment

April 23, 2020

Once again I find myself trying to learn Haskell. I’ve given up on this multiple times in the past, in no small part due to tooling issues: why is Stack trying to download so many different versions of GHC? why can’t I ever get any IDE-like functionality to work properly in Visual Studio Code?

I asked for advice from the Haskell community at the Recurse Center, and ended up deleting all my existing Stack/Cabal/haskell-ide-engine/Homebrew/??? installs and following this guide instead. The instructions were mostly correct, though a couple of things have been renamed or updated. For the sake of completeness and my own future reference, here is what I ended up doing to get a working development environment:

  • Install Stack using good old curl | sh
  • Run a Stack command (like stack path --stack-root), then hit Ctrl-C to cancel as soon as it starts trying to download GHC 8.8.something. Then, edit ~/.stack/global-project/stack.yaml and change the resolver line to the GHC version you want. I went with 8.6.5, which is referred to as lts-14.27 on the Stackage homepage.
  • Make a new project: stack new someproject; note that you still need to update the resolver in its stack.yaml, sigh
  • Install the syntax highlighting VS Code extension (justusadam.language-haskell)
  • Install the hlint VS Code extension (hoovercj.haskell-linter)
  • Install hlint globally (stack install hlint). This will take a while.
  • Clone the source for Haskell IDE Engine
  • In your home directory (or somewhere else outside of a Stack project), double-check your GHC version (stack ghc -- --version), then run the following commands in the haskell-ide-engine directory, substituting your GHC version. This will take a long while. (NB: This worked fine on macOS, but on Ubuntu, it failed at first, because one of the dependencies couldn’t link against the tinfo library. Apparently the way to fix this is by installing the development version of libncurses: sudo apt install libncurses-dev.)
stack ./install.hs hie-8.6.5
stack ./install.hs data
  • Install the Haskell Language Server VS Code extension (alanz.vscode-hie-server)
  • Install the dependencies for the debugger adapter: stack install haskell-dap ghci-dap haskell-debug-adapter. This will take a while, but not as long as HIE.
  • Install the debugger adapter VS Code extension (phoityne.phoityne-vscode)

Once you have all this stuff installed, your Haskell project should have syntax highlighting, linting/rewrite suggestions, docs/types on hover, debugger support, and probably a bunch of other cool stuff I haven’t discovered yet!