OK I GIVE UP

Learn You a Haskell for Great Good!: A Beginner's Guide

Book cover image

This unassuming book is a smart introduction to Haskell, a programming language that is notoriously hard to learn, since it’s so different from mainstream languages. At the time when it was published, the landscape for Haskell texts, especially for beginners, was relatively sparse. The only other introductory book directed towards practical daily work was Practical Haskell, a text with its own problems (see my review of it). This book filled, and is still filling, the gap for texts that give one a taste of the language, without getting too deep into the hairy bits of the language. The problem is, Haskell has a lot of hairy bits; more about this later.

The first few chapters cover the basics of what sets Haskell apart from most other languages: list processing, functional programming, the type system. The book does a particularly good job of explaning laziness, a feature of Haskell really rare among other languages. Functional programming is mostly explained with the example of functions that are already in the code base, such as takeWith or filter. In addition to this, many toy examples are employed, which is kind of annoying, but one has the feeling that the main aim of the book is not to get the developer to do, say, systems programming with Haskell, but get acquainted with its fundamental ideas.

After the easy bits with sum types and walking trees and such come the hairy bits of Haskell. The first is, you guessed it, IO. IO notoriously uses monads, one of the central abstractions of Haskell that is a pain to understand. In the Haskell type hierarchy, monads come rather late, but IO is very important for programming, so there is no point in putting it at the end of the book. For this reason, the author chooses to introduce the IO monad without making a big fuss of monads. Instead, the simple operations are explained in a “this is how you do it, don’t care about the rest” manner. This attitude is common to many other Haskell texts, but it’s still a bit weird.

The rest of the book deals with the most fundamental abstractions of Haskell, or rather of functional programming as embodied in Haskell: functor, applicative functors, monoids and monads. The instances of the most important types (lists, functions, tuples) for these typeclasses are explained in detail. The examples are sometimes too toy-like, but the level is appropriate for such an introduction to introduction book. The last chapter is a study of how simple procedures such as traversing and modifying lists is done in functional programming where side effects are not allowed. While reading it, I had quite a few “that’s how you do it!” moments.

If you would like to have an idea of what Haskell is about, this is probably the best book you can get.