On Wed, Feb 4, 2009 at 11:41 AM, Tim Newsham <newsham@lava.net> wrote:
I put up a small Monad explanation (I wouldn't quite call it
a tutorial):
 http://www.thenewsh.com/~newsham/haskell/monad.html

"The values of the IO monad are programs that do IO. "

That's a fairly common representation, seems to work for lots of people, but it caused me no end of trouble.  Values are mathematical objects; how, I asked myself, can they possibly /be/ programs that do IO (or actions, or computations, or <your metaphor here>)?  It doesn't make sense, says I, so I must be misunderstanding something about "values"; better spend hours and hours researching and trying to figure this out.  But it turns out the answer is simple: they can't.  They're not actions, or IO procedures, or anything else other than plain old mathematical values, no different than '2' or Int -> Char.  They happen to correspond in some way to the external physical behavior of the program, but that correspondence is an implementation detail beyond the scope of the formal (mathematical) semantics of the language.  You don't even need monads for this part; they only enter the picture in order to provide ordered evaluation.  In fact there really aren't any "monadic values", since a monad is pure morphism; the values at issue are "functoric values" if anything.  It's (the implementation of) getChar the does the IO, not IO Char.

So you could say that the monad itself is a purely mathematical structure that has the felicitous if accidental side effect of imposing temporal sequence on the physical interpretation (events) associated with  the program.

-g