Haskell with VsCode DevContainers on M1.

source: https://www.reddit.com/r/ProgrammerHumor/comments/o30ewa/haskell_in_one_meme/)

I’ve been interested in haskell for quite sometime and decided to pick it up finally. So the first thing I needed to do was setup my development environment. Looking for a good dev environment setup on M1 is a bit difficult. After a few hurdles, I was able to come up with a minimal setup.

I’m quite used to VsCode remote containers and I wanted to do the same here and configured the following in the dev container:

1. Setup

Following the official haskell dev-container documentation from microsoft, the first step is to create a project directory and.devcontainer directory under it. Then create the following files with their respective contents:

1.1 devcontainer.json

1.2 Dockerfile

2. Extend

Once I had the basic setup, I needed to update the .devcontainer.json file and add the following settings. I’ve used the haskell.manageHLS to specify that I’ll manage my own installation of GHCup because the extension doesn’t come with GHCup and I needed it for the toolchain installation. You can read more in the documentation here.

I also needed to extend the Dockerfile and add a few dependencies for the haskell vscode extension to install the toolchain.

3. Code

At this point, I had the basic environment setup that I was able use to initialise a haskell app and get started. I’ve loaded the directory onto vscode. If you have it already open, you can reload the window and it’ll rebuild the dev container which will take a few minutes.
Once that’s done, and the project is successfully loaded onto vscode, I needed to open the terminal inside vscode (i.e the session from within the container, if you prefer to use a separate terminal window, you’ll need to attach it to the running haskell dev container.) and run the following commands.

cabal init # Create app
ghci :l app/Main # load main module
main #call main function which will print "Hello, Haskell!"

Here’s the complete repo.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anteneh Aklilu Metaferia

Anteneh Aklilu Metaferia

Software Craftsman | Product Development | Cloud Computing | Payments | Lean + Agile Methodologies