
Brian Hulley wrote:
Yitzchak Gale wrote:
I wrote:
Prelude> let f = undefined :: Int -> IO Int Prelude> f `seq` 42 *** Exception: Prelude.undefined Prelude> ((>>= f) . return) `seq` 42 42 The monad laws say that (>>= f) . return must be identical to f.
I thought it was:
return x >>= f = f x
so here the lhs is saturated, so will hit _|_ when the action is executed just as the rhs will. I think the problem you're encountering is just that the above law doesn't imply:
(>>= f) . return = f
in Haskell ok so far...
because the lhs is of the form \x -> _|_
No I got this wrong. Evaluating the lhs to WHNF doesn't hit the _|_. (Incidentally the version using .! evaluates to exactly the same thing since (>>= f) `seq` ((>>= f) . return) = ((>>= f) . return) since (\x -> x >>= f) is already in WHNF afaiu) Brian. -- http://www.metamilk.com