Learn You a Haskell for Great Good! -- Book review
Full disclosure: I was given a review copy of the book.
“Learn You a Haskell for Great Good,” by Miran Lipovaça, is a Haskell “Beginner’s Guide.” The author has really nailed the tutorial style in written form: at each step, you follow along with what he wrote and say “that’s obvious”, and at the end you’ve learned something incredibly important. It’s verbose, but that’s what is called for in a tutorial like this one. It is for Haskell beginners – that includes expert imperative programmers as well as complete programming novices. This book has some material for intermediate Haskellers, but not too much.
The beginning is suitable for nearly anyone to learn the basics. After the first 2 chapters, and with a healthy dose of creative thinking, a smart person with no programming experience will be able to solve tons of small problems at the ghci prompt. One thing I thought was missing was how to fix type errors – I couldn’t find any examples of a type error in the first few chapters, but type errors are often confusing and I think a newbie is likely to hit a lot of them.
The book moves on to functions and functional programming and typeclasses before it touches I/O. This is a great approach; it frees the beginner from dealing with messy monadic actions and such before they’re ready. To write useful programs, it teaches loading functions into ghci and running them that way – putStrLn is not introduced until the reader is ready to hear about files.
There’s a chapter on “functionally solving problems” which I really appreciated. The author shows how to solve two puzzle-scale problems, RPN calculator evaluation and a shortest-path problem, in idiomatic fashion in Haskell. The rest of the book is mostly tiny toy examples, so it was nice to have some cool programs to show off how fun it is to write functional code.
There’s a great three-chapter sequence that introduces functors, applicative functors, monoids, and monads. This is the real value of this book: an accessible, no-nonsense, practical walkthrough of the real abstraction workhorses of Haskell, those magic typeclasses which, once grokked, really warp your thinking about code. If you don’t quite understand applicative functors, or the implementation of a monadic bind function, that’s where this book will be useful to even an intermediate-level Haskell programmer.
The last chapter is a seemingly tacked-on explanation of zippers – a trick for building efficient data structures in functional languages. I appreciated it because I hadn’t seen much about zippers before, but I didn’t understand how it fit into the rest of the book.
Overall I am really impressed with this book. As noted, the style is very much a tutorial: step by step the author will teach you important material in an easy-to-follow way. It’s not good reference material: there’s no reason to keep the book by your desk in the long term. It’s designed to be read through carefully while following along.
I will contrast LYAH with Real World Haskell, another Haskell book which I own. RWH is not quite as beginner-oriented, though a Haskell beginner could learn to program using it. LYAH’s applicative functor and monad tutorials are much better than those in RWH. But RWH is much better as reference material for lots of things I do regularly, like parsing and the FFI.