State monads don't respect the monad laws in Haskell
Ross Paterson
ross@soi.city.ac.uk
Tue, 14 May 2002 13:42:34 +0100
On Tue, May 14, 2002 at 12:14:02PM +0100, Simon Marlow wrote:
> The question we were considering was whether the following should hold
> in the IO monad:
>
> (return () >>= \_ -> undefined) `seq` 42 == undefined
>
> [as implied by the left-identity monad law]
>
> This discrepancy applies to any state monad.
It also fails for the reader, writer and continuation monads, also thanks
to lifted functions and tuples. The right-identity law also fails for
these monads:
(undefined >>= return) `seq` 42 /= undefined `seq` 42