Contents

Playing with Haskell

While I was reading Seven Languages in Seven Weeks 1, I wanted to test Haskell. Just for fun.

Running Haskell

To run Haskell one solution is to use a Docker image. It avoids the burden of installing it on your machine.

To make it even easier, a good old Makefile can help.

# Assuming you have an src folder it will run the image
# and mount the src volume in /root/src
current_dir = $(shell pwd)
image = "haskell"
tag = "8"
image_tag = "${image}:${tag}"

GHCi:
	@echo "Running ${image_tag} in console mode ..."
	@docker run -v ${current_dir}/src:/root/src -w "/root/src" -it --rm ${image_tag} ghci

Once defined, to run GHCi (stands for Glasgow Haskell Compiler Interactive), just run the make.

$ make

# Running haskell:8 in console mode ...
# Unable to find image 'haskell:8' locally
# 8: Pulling from library/haskell
# 146bd6a88618: Pull complete
# 27eaafd2ddfb: Pull complete
# Digest: sha256:e6b4675835bce283d610179c3ee67840ce9b702745f1f7709c121e07d41e0c5d
# Status: Downloaded newer image for haskell:8
# GHCi, version 8.8.1: https://www.haskell.org/ghc/  :? for help

Prelude>

Playing with it

Now you can start playing.

-- A dumb example
Prelude> double x = x + x
Prelude> double 4
8

Next steps

My advice is to read the great book Learn You a Haskell for Great Good! 2. Even better, it can be read online for free.


  1. Bruce A. Tate, Seven Languages in Seven Weeks, 1ʳᵉ éd., O′Reilly, 2010, 368 p. ↩︎

  2. Miran Lipovaca, Learn You a Haskell for Great Good!: A Beginner’s Guide, No Starch Press, 2011, 400 p. ↩︎