» Review of "Programming in Haskell" #

Paul R. Brown @ 2007-02-24

I pre-ordered a copy of Programming in Haskell by Graham Hutton from Amazon last year, and once it showed up last month, its ~150 pages were a quick and pleasant read.

For an experienced programmer who's happy with dirt under their nails, materials for learning Haskell are available on line: the classic Gentle Introduction to Haskell, the Haskell Wiki, and the Haskell Report (language specification and source code for core libraries). Also, the folks on Haskell Cafe and the Haskell IRC channel are generally receptive to beginner questions that aren't obviously homework...

And this brings me to the first strength of the book: the stated target audience for Programming in Haskell is the "absolute beginner", and the book does a good job playing to that audience. Recursion, higher-order functions, and laziness all appear in the book but relatively late and with a good amount of supporting exposition and some rules of thumb. Formal reasoning about Haskell programs (proof by computation, induction, etc.) appear only in the last chapter, and IO is presented without more general discussion of monads but with adequate discussion of the conflict between side-effects and a purely functional language.

The book's other major strength is in the examples. Each chapter includes compact, uncontrived, and interesting examples, which is a major feat for any textbook. I particularly liked the Caesar cipher and Countdown examples. I can see this being a good textbook for an introductory course, and with lecture slides available from the site for the book and supporting materials available from the publisher, the author has clearly gone out of his way to make it a good choice as a textbook.

As for non-positives, I've already spent time mucking through the online materials about Haskell and on a few other books on the topic (The Haskell Road to Logic, Maths, and Programming, The Haskell School of Expression, and Purely Functional Data Structures), so I didn't take any new knowledge about Haskell away from the book. Nonetheless, I did find a few things to take away from the book, e.g., a technique for compactly generating the powerlist (all sublists) of a list that was part of the Countdown example.

Other than the price seeming a bit much on a per-page basis, the only other thing that bugged me about the book — and only because I used to be a working mathematician — was this statement about the Game of Life on p. 94:

That is, we can think of the board as really being a torus, a three-dimensional doughnut-shaped object.

The game board is indeed a torus, but a torus is a two-dimensional object. One representation of a torus embedded in three-dimensional space would be as the surface of a doughnut, but that representation is not what defines a torus. A torus is a two-dimensional surface obtained as the cartesian product of two circles. An equivalent construction is to create a torus by gluing opposite sides of a square, like so:

Living on a torus with the usual metric is like playing Asteroids; if you fly off the {top,bottom,left,right} of the screen at some angle, you fly on the {bottom,top,right,left} at the same angle. Or, to put it another way, if you were a two-dimensional creature, it would be like being on a plane where there were infinitely many copies of you, placed at points with two integer coordinates. While this is admittedly a bit of a niggle, I emailed Graham, so hopefully this shows up as an erratum.

 

← 2007-01-24 — Laziness and fizzbuzz in Haskell
→ 2007-09-15 — Emacs haskell-mode Unicode Cuteness