[Haskell-cafe] Monads, do and strictness

Roman Cheplyaka roma at ro-che.info
Sat Jan 21 18:57:23 CET 2012

* Victor S. Miller <victorsmiller at gmail.com> [2012-01-21 12:29:32-0500]
> The "do" notation translates
> do {x <- a;f}  into
> a>>=(\x -> f)
> However when we're working in the IO monad the semantics we want
> requires that the lambda expression be strict in its argument.

I'm not aware of any semantics that would require that.

According to a monad law,

  return x >>= f

should be equivalent to (f x). In particular,

  return x >>= const (return ())

is equivalent to (const (return ()) x) or simply (return ()).

So, const is non-strict in its second argument even when used in (>>=).

Roman I. Cheplyaka :: http://ro-che.info/

More information about the Haskell-Cafe mailing list