Saturday, May 2, 2009

Learning about monads: some suggestions

So, I'm relatively new to Haskell, and I have to say that monads were a part of the language that took me a while to get comfortable with. This post is not a tutorial... there are already many monad tutorials out on the web that do a better job than I would. Instead this post contains a few of my "lessons learned" about how to best use your time when you are learning monads.
  1. My biggest suggestion is that you understand that there is nothing "special" about monad types. In my initial attempts to learn monads a lot of the material I read left me with the impression that monads somehow play by different rules than the rest of the Haskell language. The monad class is a plain old Haskell class that just happens to define an interface that is very useful for implementing a particular design pattern that shows up often with things like IO and error propagation.
  2. Don't expect to fully understand monads until you feel comfortable with higher-order functions (functions that take functions as arguments) and Haskell's type system (classes). The Learn You a Haskell tutorial is a lot of fun and provides a good introduction to these prerequisites.
  3. The "do" notation is useful for formatting reasons but it can also help to reinforce the idea that monads are somehow special. I recomend that you start learning how to use the >> and >>= functions for monads sooner rather than later so that you will see how monads work in a way that is consistent with the rest of Haskell.
  4. I also think its useful to read some opinions that are critical of monad tutorials so that you can make better decisions about how to spend your time. See: Brent's post on monad tutorials and a blog post on why monad tutorials are awful.

0 comments:

Post a Comment