[Haskell-cafe] Re: Explaining monads

David Roundy droundy at darcs.net
Mon Aug 13 18:01:01 EDT 2007

On Mon, Aug 13, 2007 at 05:13:01PM -0400, Brandon S. Allbery KF8NH wrote:
> On Aug 13, 2007, at 16:29 , Benjamin Franksen wrote:
> >Let's take the simplest example: Maybe. The effect in question is the
> >premature abortion of a computation (when Nothing is returned). And of
> >course Maybe sequences these effects, that's what you use it for: the
> >_first_ action to be encountered that returns Nothing aborts the
> >computation. Clearly sequencing goes on here.
> Clearly it does, but not as a side effect of the *monad*.  It's ordinary
> Haskell data dependencies at work here, not some mystical behavior of a
> monad.

It's the *effect* of a monad, not the *side* effect.  The type of >>=
defines this dependency.  And when you have a chain of dependencies, that
is sometimes referred to as a sequence.  True, it's not mystical, but it's
still sequenced.

Try executing:

  do { x <- return 2; undefined; return (x*x); }

in any monad you like, and you'll find that regardless of the *data*
dependencies (the return value of this monadic action is unambiguous), the
undefined is evaluated *before* the value 4 is returned.
David Roundy
Department of Physics
Oregon State University

More information about the Haskell-Cafe mailing list