The is a simple labyrinth builder "game" for my son, written in Haskell and using GTK+ and Cairo. It started as a project to learn Rust, but it turned out to be written in Haskell.
The original Rust implementation can still be found here, but is much less complete.
It is possible to draw a labyrinth, to place and start and end points and compute the shortest way through the labyrinth. It is possible to save/load labyrinths to the harddisk.
One great source of fun when using Haskell, are the different ways to build a project. There are at least four different ways to build this one, using a disjoint set of tools. I recommend using stack and (optionally) nix.
This installation option has the advantage, that the native operating system libraries are used. Also much less hard disk space is wasted. As a disadvantage, llvm
can not be used as a ghc
backend, except if you have a very old Linux distribution which still provides llvm 3.9
.
- Install prerequisites
On Debian, this is something like:
apt-get install libgirepository1.0-dev libgtk-3-dev libcairo2-dev build-essential cmake
- Install stack
curl -sSL https://get.haskellstack.org/ | sh
- Build project
stack build
In opposite to the installation option via stack
alone, this also automatically provides all dependencies in a container like manner. As an additional advantage, one may use the llvm
backend for ghc
. Note that this uses a lot of hard disk space, around 2.5 GB
for Nix and 3 GB
for stack. Luckily, the stack and nix repositories can easily be deleted by removing ~/.stack
and /nix/
.
- Install stack
curl -sSL https://get.haskellstack.org/ | sh
stack is nowadays the best way to build Haskell projects. It is like the combination of rustup
and cargo
in the Rust world. Especially it automatically installs (eventually multiple) versions of ghc
, the Haskell compiler.
- Install nix
curl https://nixos.org/nix/install | sh
nix is like stack
for external dependencies, like operating system libraries. It ensures that the build is made in some closed container, independent of the environment of the underlying operating system. The stack.yaml
configuration automatically builds inside a nix container, so you do not have to envoke any nix
commands by yourself. Note that nix
uses alot of space inside /nix/store
. A basic set of packages used for building hlabyrinth
is about 2 GB.
- Build the project
stack --stack-yaml stack-nix.yaml build --flag hlabyrinth:llvm