Melodramatic? Maybe, but I began to understand what a Monad might be in the Haskell language tonight. I’ve been banging my head against the wall trying to understand them. Finally, I decided to read the Haskell 98 Report (something I would never have done until I met a certain Russian friend who actually reads the manuals and specifications out there… it turns out that’s a pretty good idea.)

So here’s what the Report has to say about Monads:

A do expression provides a more conventional syntax for monadic programming. It allows an expression such as

  putStr "x: "    >>
  getLine         >>= \l ->
  return (words l)

to be written in a more traditional way as:

  do putStr "x: "
     l <- getLine
     return (words l)

Ahah! The do syntax creates a sequence of anonymous closures! Not only that, but each closure gets a single value (optionally) bound to a variable, so that, for example, in the case of the IO Monad, it appears we are stepping through time as a sequence of events.

Now I just need to understand why these Monad things are so valuable that we need to go through this convolution in the first place…