Minimal Haskell Dev Setup on Ubuntu

This documents the steps required to prepare a development environment for Haskell in Ubuntu. All of this is straight-up jacked from here. I’m brand new to the Haskell ecosystem. I am learning the language so that I can build and test Plutus smart contracts on Cardano.

Note to Plutus Pioneers: the following instructions are not executed from within the context of nix (i.e., I’m not running nix when I’m running these commands…)

Basic tool setup

First, install some system dependencies:

1
sudo apt install build-essential curl libffi-dev libffi6 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5

Then, install GHCup:

1
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

You will be prompted to make some decisions. I generally like to stick with defaults, and that’s mostly true here. However,

  1. I answered Y to installing the haskell-language-server. This is so I can leverage language features in my favourite editor, vim.
  2. I answered Y to installing stack. Here’s some context.

At the end of it, you should have GHC, cabal-install, stack, and haskell-language-server.

In all the steps taken so far I’m not sure what went wrong, but stack never actually arrived. Thankfully, the Haskell docs provide a backup:

1
curl -sSL https://get.haskellstack.org/ | sh

Optional: Configure the Language Server for Vim

vim is the only editor I use. If you have the haskell-language-server installed, you can do something similar with your favourite tool.

I tried to take the path of least resistance by using the Coc configuration/installation instructions. Again, I’ve purposefully avoided executing within the provided Plutus nix-shell environment. The instructions are distilled as follows…

Install vim-plug:

1
2
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Configure vim-plug:

1
vim ~/.vimrc

Paste this somewhere toward the top of the file where you won’t be busting up any logical blocks:

1
2
3
4
5
6
7
"""
" vim-plug extensions
call plug#begin('~/.vim/plugged')

Plug 'neoclide/coc.nvim', {'branch': 'release'}

call plug#end()

Run this command in vim:

1
:PlugInstall

This will download whatever plugins are included before the plug#begin and plug#end.

Again, issue this command in vim:

1
:CocConfig

Paste this into the Coc config file:

1
2
3
4
5
6
7
8
9
10
{
"languageserver": {
"haskell": {
"command": "haskell-language-server-wrapper",
"args": ["--lsp"],
"rootPatterns": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml"],
"filetypes": ["haskell", "lhaskell"]
}
}
}

Bootstrap a project with Stack

I spend most of my time in a node environment. If you’re familiar with the Javascript ecosystem, stack appears analagous to npm.

To start a new project with the default template, navigate to your preferred project directory and initialize:

1
2
3
cd ~/workspace
stack new my-project
cd my-project

You now have a directory containing almost everything you need to start work. Facilities for testing are sketched in but aren’t actually configured when bootstrapping from the default template.

Just for fun, try:

1
stack test

You can also build the minimal project:

1
stack build

And execute:

1
stack exec my-project-exe

To launch the REPL:

1
stack ghci

Haskell and all it’s goodies, ready to go.

Next up… I’m figuring out testing tools.