Programming in Haskell

John Hughes These are the teaching materials for the introductory programming course given at Chalmers University to computing students (excluding a small fraction which are still in Swedish), organised to make them easier to use for self-study. The course teaches programming using Haskell, to students who in many cases have never programmed before. Experienced programmers learning Haskell will find parts of the material elementary, but hopefully will still find much to interest them. Although the course is introductory in nature, it does sketch some recent research and industrial applications of functional programming.

The course is organised as seven units, each taught during one week. Most units contain lectures, group exercises, and laboratory work. The slides of the lectures are all on the web; they are intended also to serve as notes for students, so should be comprehensible in isolation. The group exercises are intended for discussion with a tutor, and some are quite difficult: why not persuade a friend to learn Haskell with you, so you have someone to discuss them with? Simpler exercises can be found in the text book. The laboratory problems start small and become more substantial projects stretching over several weeks by the end of the course.

Text book

The course is loosely based on

Simon Thompson, Haskell - The Craft of Functional Programming (second edition). Addison-Wesley, ISBN 0-201-34275-8, 487 pages, paperback, 1999.

The lectures follow the first chapters fairly closely, then branch out to discuss among other things recent research. Make sure you use the second edition: the first is not as good, and the exercises are different, so exercise numbers in these materials will not match the book.

Thompson's book is very pedagogical, and helpful especially if you're having difficulties. If you're an experienced programmer, and ready for a rougher, but more exciting ride, then I would recommend Paul Hudak's book instead:

The Haskell School of Expression: Learning Functional Programming through Multimedia by Paul Hudak, Yale University. Cambridge University Press, New York, 2000. http://www.haskell.org/soe/.

This is a great book, but definitely not for beginners to programming, in my opinion.

Downloading Haskell for Windows 95/98/NT

If you want to install Haskell on your computer, you can download Hugs98, the version of Haskell that the course uses, from the Hugs98 home page. This site contains information on all the various versions of Hugs, and on Haskell in general. Windows users can just download a self-installing executable.

Course Units

Unit 1: Introducing Haskell

Lecture 1: Introduction to Haskell. (Powerpoint, Printable version). Reading: Chapter 1.
Lecture 2: Function Definition by Cases and Recursion. (Powerpoint, Printable version). Reading: Chapter 3.1-3.4, 3.7. Chapter 4.

Exercises: Recursion on natural numbers. Solutions

Laboratory Work:
(Swedish introductory exercises omitted).
An introduction to scripting in Haskell (optional, UNIX specific).

Unit 2: Basic Data Structures

Lecture 3: Tuples and Lists. (Powerpoint, Printable version). Reading: Chapter 5.1-5.7.
Lecture 4: Pictures, A Case Study. (Powerpoint, Printable version). Reading: Chapter 6.1, 6.3.

Exercises: Lists and Comprehensions. Solutions

Laboratory Work: Supermarket Billing

Unit 3: Recursion on Lists

Lecture 5: Recursion on Lists. Powerpoint, Printable version. Reading: Chapter 7.1-7.5.
Lecture 6: Case Study: Route Finding. Powerpoint, Printable version.

Exercises: Recursion on lists Solutions

Laboratory Work: (Drawing Graphs, in Swedish, omitted).

Unit 4: Higher-Order Functions

Lecture 7: Higher-order Functions. (Powerpoint, Printable version).

Exercises: (Swedish exercises omitted).
Some simpler "revision style" exercises.

Laboratory Work: (Drawing Graphs continued).

Unit 5: Testing and Debugging Tools

Lecture 8: Testing and Debugging. (Powerpoint, Printable version).

Exercises: A variety of harder exercises.

Laboratory Work: a choice between two projects.

Unit 6: User-Defined Types

Lecture 9: Defining New Types. Powerpoint, Printable.

Exercises: Exercises on User Defined Types. Solutions

Laboratory Work: continuation from Unit 5.

Unit 7: Functional Programming for Real

Lecture 10: Industrial Functional Programming and the Programming Contest. (Powerpoint).

Here is Beating the Averages, an entertaining article on industrial functional programming in Lisp by Paul Graham.

If you find these materials useful, then drop me a mail! Comments are welcome.

Exam Papers

Interesting Links

There is a great deal of information on functional programming on the Web.


Last modified: Thu Jan 10 16:25:15 MET 2002