by lobster_johnson · 14y ago · 0 comments
Books such as "Real World Haskell", the "gentle guide" and "Yet Another Haskell Tutorial" all manage the rather unbelievable feat of making many Haskell concepts unnecessarily complex, unintuitive and hard to understand -- not something you want for a language that is already on the complex side. For example, RWH goes into an absurdly complicated sample scenario (a parser, iirc) to introduce the reader to monads, and never slows down to go back to first principles. YAHT does the same thing.
Monads have a reputation for being hard to understand, but I think this is mostly the fault of the current literature; monads are conceptually simple, yet every book manages to botch their explanation, making the learning curve particularly steep for non-FP programmers.
And I disagree a bit about RWH... I'm in the middle of it now I think it's great, filled with meaty examples that aren't too complicated at all and are generally pretty concrete. Maybe I'm just not far enough in yet? There are bits where it goes off into the weeds (the chapter on JSON goes so far as to fiddle about with character encoding IIRC) but I just can't imagine a PragProg book could do much better, without sacrificing depth.
Personally, my "eureka" moment was reading the "IO Inside" [1] page on the Haskell wiki, which explains the IO monad in a way that made it click for me, as a imperatively-trained programmer. You can think of the IO monad as a way to force a compile-time dependency between I/O operations by having each IO-performing function take a "baton" value (the "IO" instance) as an argument, as well as return it. The explanation of how Haskell retains the appearance of purity in the face of impure I/O by passing an instance of RealWorld around is genius. That's a brilliant way to start out explaining monads, and it's something simple that you can use to explain the other monads such as the state monad (which the IO monad is built on).
I haven't tried the Hutton book yet.
That said, it is about programming in Haskell and not about programming with Haskell; hence this series of articles where I try to look at the wider picture and some pragmatic issues.
About monads, seeing them outside of Haskell is a great way to see smaller steps. Articles like http://dorophone.blogspot.fr/2011/04/deep-emacs-part-1.html , or this video http://www.youtube.com/watch?v=ObR3qi4Guys
I hope it will help you
Monads are a useful technique, but they aren't everything!
What else would you like to see in such a book? http://forums.pragprog.com/posts/30455
Personally, I like the "Learn You A Haskell" style, of carefully and very gently building up the basic language, with examples that are as simple as possible and deal with only the issue being discussed. My problem with Real World Haskell is that it combines learning the language with building stuff. So when it gets to something like monads, there are way too much noise surrounding the core concept being explained. It's fine to show practical examples, but not everything should be built on them.
Aside from that, I like the practically-oriented stuff in RWH. I would like to see an article on doing concurrent, parallel, distributed systems (Erlang-style) in Haskell.