An interesting revelation just occurred to Simon P.J. and myself while
wondering about issues to do with exceptions in the IO monad (see
discussion on [EMAIL PROTECTED] if you're interested).

The question we were considering was whether the following should hold
in the IO monad:

        (return () >>= \_ -> undefined) `seq` 42   ==  undefined

as we understand the IO monad it certainly shouldn't be the case.  But
according to the monad laws:

        (law)  return a >>= k  ==  k a
        so     (return () >>= \_ -> undefined) `seq` 42
      =>     ((\_ -> undefined) ()) `seq` 42
      =>     undefined `seq` 42
        =>     undefined

So the IO monad in Haskell, at least as we understand it, doesn't
satisfy the monad laws (or, depending on your point of view, seq breaks
the monad laws).  

This discrepancy applies to any state monad.  Suppose we define

        return a = \s -> (s, a)
        m >>= k = \s -> case m s of (s', a) -> k a s'

now
           return a >>= k
      => \s -> case (return a) s of (s', a') -> k a' s'
        => \s -> case (s, a) of (s', a') -> k a' s'
        => \s -> k a s

        but (\s -> k a s) /= (k a) in Haskell, because seq can
        tell the difference.

What should the report say about this?

Cheers,
        Simon
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to