Learn You a Haskell for Great Good!

Author: Miran Lipovaca
Publisher: No Starch Press, 2011
Pages: 400
ISBN: 978-1593272838
Aimed at: Beginners to Haskell
Rating: 4
Pros: Provides an introduction to Haskell
Cons: Avoids formal definitions making many ideas seem difficult
Reviewed by:Alex Armstrong

This book has a big blue elephant on the cover and a strange title - can this help you understand Haskell and functional programming in general?

The simple answer is that in this case it doesn't but in general a blue elephant could be of great help.

The back jacket claims -

Learn You a Hakell for Great Good is a hilarious, illustrated guide to this complex functional language.

Well I for one didn't even raise a smile and the illustrations often seemed irrelevant to the text. When they were relevant they didn't add anything and they certainly never added any noticeable humour. The same is true of the text. It is written in a friendly and informal style but, funny? No.

The point is you could take a classic text on special relativity or very difficult differential equations, give it a strange title and cover it in small sketches - the result would be just as difficult to comprehend.

The first thing to say is that Haskell isn't a difficult language to understand. It is one of the more "extreme" functional programming languages but if you understand the principles of function programming it isn't difficult. However functional programming is an academics sort of language in that it helps if you know things from other areas of study. For example if you know what a monoid is from mathematics then what a monoid is in a functional programming language is fairly straightforward - how to use one is another matter. So although the book is subtitled "A Beginner's Guide" - you still need to be a sophisticated beginner to get much from it, even though it has a blue elephant on the cover.

The book even starts in an irritating way. There is an introduction before Chapter 1. Don't you often skip introductions? I do and clearly the author knows that readers do as Chapter 1 opens with:

"If you are the horrible sort of person who doesn't read introductions, you might want to go back and read the last section anyways - it explains how to use this book as well as how to load functions with GHC."

Then again if  you are the horrible sort of author who puts important stuff in the introduction you might want to go back and rewrite the start of the book to eliminate the introduction. On the other hand this might be part of the hilarious humour eluded to on the back jacket...

The chapter opens gently enough with a discussion of entering expressions interactively. This part is easy because what you are doing is easy. The amount of information slowly ramps up to functions, lists, list comprehensions and tuples - all introduced with a light touch but nothing deep.

Chapter 2 moves on to types in Haskell, which is a topic that programmers from other language backgrounds find hard. However, the author isn't very careful about using words that might mean things to programmers. For example, page 27:

"A type class is an interface that defines some behavior"

OK so most programmers would decide that class wasn't being used in an object-oriented sense but interface? But wait, the next line starts:

"If a type is an instance fo a type class... "

so perhaps it is used in the object-oriented sense, so now what about interface? Another problem is that, in the effort to be easy to understand, accurate definitions are generally avoided but if you don't already know what the syntax is you can be left wondering what it all means.

Chapter 3 moves on to consider functions and this takes a lot of space to explain something that would be easier to understand with a more formal definition. Haskell's pattern matching approach to function definition isn't difficult but it is made to seem mysterious in that you can't see how general a pattern can be.

The next big topic is recursion, as it must be in any book on functional programming. The author manages to give a good example but doesn't really motivate recursion as a way of dealing with the key differences in a functional language - immutability and no loops. Even when the repeat function is introduced - implemented recursively of course - the connection between recursion and iteration isn't made. The final example is of a quicksort, which is fine if you have actually got the idea of recursion. The beginner might think that to use recursion you have to invent ideas like the quicksort every time - which really would make functional programming hard.

Chapter 5 moves on to consider higher order functions - currying and lot of functions that use functions. Then we lambdas, folds, etc. Then on to practical matters in the form of modules. The chapter ends with creating custom modules and the next chapter continues with a look at creating custom types and type classes. Chapter 8 and 9 are on I/O  including files and streams.

Chapter 11 returns to more pure functional programming with a look at applicative functors. Functors were introduces in Chapter 7 as part of first class functions but now we have to study them in detail. The definitions are difficult to follow but the examples help. Chapter 12 continues the ascent of Haskell with an introduction to monoids. At the end of the chapter you should be able to say what a monoid is but you probably aren't sure why you need to know. This is the question Chapters 13 and 14 are designed to answer and the final chapter is an example of a tree walk.

So at the end of the whole book will you be able to program in Haskell? Possibly but you will have had to work very hard. The illustrations don't help much but the style of writing is relaxed if not humorous. This isn't a bad book on Haskell but occasionally it would be better if instead of working around a topic it simply resorted to a short formal definition.

It also doesn't make much use fo the fact that most, if not all of its readers are likely to be programmers, and hence understand various ideas. You could introduce recursion by contrast with iteration, you could explain first class functions by talking about delegates or function objects, and you could explain functors by pointing out that they are not function objects. It also lacks any real motivation as to why we should go to so much trouble to make programming seem complicated or more like pure maths. 

Put another way, despite its best attempts this book is just not a revolution or a revelation. It just covers the material.  There is a better book on Haskell yet to be written that explains it in a straightforward manner to the working programmer.  Until that book comes along you might want to buy this one for the blue elephant on the cover...

Last Updated ( Friday, 03 June 2011 )