[Haskell-cafe] IO is not a monad
Brian Hulley
brianh at metamilk.com
Tue Jan 23 14:05:06 EST 2007
Brian Hulley wrote:
> 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.
Ooops! But that does not mean the equation holds because for example
Prelude> (return 3 >>= f) `seq` 42
42
Prelude> (f 3) `seq` 42
*** Exception: Prelude.undefined
In the lhs you only hit _|_ when the composite (>>=) action is actually
being executed whereas in the rhs you hit _|_ when computing the function
which will return the action to execute so there is difference.
Brian.
--
http://www.metamilk.com
More information about the Haskell-Cafe
mailing list