July 25th, 2010

Yet Another Monad Tutorial (part 1: basics)

It's a standing joke in the Haskell community that every Haskell programmer, as part of his or her learning process, will eventually write one or more monad tutorials. I'm certainly no exception. But since I know that there are already dozens of monad tutorials out there, some quite good, why on earth would I want to write Yet Another One? There are two reasons:

  1. I think I can explain some aspects of monads better than most of the monad tutorials I've seen.

  2. My own understanding of monads has improved greatly, and I'd like to try to pass that on if I can.

Collapse )

Yet Another Monad Tutorial (part 4: The Maybe and List Monads)

In the previous articles in this series, I covered the conceptual basis of monads, but the discussion was pretty abstract. Now that (I hope) you have a pretty good idea of what monads are and what they're for, it's time to get into the nitty-gritty details of how to actually derive the definitions of specific monads. That means that we are going to have to define the correct instances of the type class Monad for the various notions of computation we talked about previously. In our derivations, we will use our understanding of how monadic composition should work in each particular case to give us the definition of monadic apply (the >>= operator), and we'll use the monad laws to give us the definition of return.

Collapse )