Haskell in Space


During the 2001 winter term I taught Haskell to our second-year undergraduates (see the course's home page). After going through the usual motions of typing, polymorphism, higher-order functions and quicksort in one line, the last exercise was to write a wee asteroids-type game. I thought this might be interesting (or at least amusing) to other students and teachers of Haskell, hence this web-page.

The exercise

The game uses the Hugs Graphics Library, plus a small home-grown geometry library (Geometry.hs) on top of it for displaying and manipulationg geometric objects. During the lecture, the geometry library was developed, and a small program was demonstrated which allowed to navigate a space ship (Space.hs). The exercise was to extend this program to an asteroids-type game, i.e. to add asteroids, and have the space ship fire bullets.

If you read German, you can have a look at the lecture slides and the exercise sheet.

The solutions

One group of students (exercises are solved in groups of up to four here in Bremen) calling themselves the Haskellies went to quite amazing lengths in their solution --- different ship shapes, background pictures, colourful explosions, and features such as the "starburst" are just the highlights. On the other hand, the reference implementation (by yours truly) is nice, clean and boring.

Here are compiled binaries for x86 Linux (SuSE 7.3, but should run on other Linuxen as well): haskelly, reference implementation.

Here is a tarball containing the sources. You will need the Hugs Graphics Library (HGL), Version 2.0.4, to compile or run the solutions:


The exercise was fairly popular with the students, as it demonstrated that Haskell can be used for things other than sorting lists, and to good effect. Using ghc, runtime performance was not an issue; under Windows even Hugs copes quite well.

Christoph Lueth
Last modified: Fri Apr 5 18:05:50 CEST 2002