[Haskell-cafe] Re: Explaining monads

Tillmann Rendel rendel at rbg.informatik.tu-darmstadt.de
Mon Aug 13 18:34:55 EDT 2007

David Roundy wrote:
> 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.

How can a Haskell type define a data dependency? Haskell functions are 
non-strict, so they may choose to ignore arguments, and ignored 
arguments are not evaluated at all.

> 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.

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


More information about the Haskell-Cafe mailing list