Gmane
From: Isaac Dupree <isaacdupree <at> charter.net>
Subject: The Proper Definition of (evaluate :: a -> IO a)
Newsgroups: gmane.comp.lang.haskell.libraries
Date: 2007-05-05 12:03:57 GMT (1 year, 13 weeks, 5 days, 3 hours and 1 minute ago)

The obvious "evaluate x = x `seq` return x" fails one of the following
laws for evaluate:

"
evaluate x `seq` y    ==>  y
evaluate x `catch` f  ==>  (return $! x) `catch` f
evaluate x >>= f      ==>  (return $! x) >>= f

Note: the first equation implies that (evaluate x) is not the same as
(return $! x).
"

However, strictness does not obey the monad laws. A correct definition
for IO would be "evaluate x = (x `seq` return x) >>= return", or
equally, "(return $! x) >>= return", or even more horrible-looking,
"fmap id (return $! x)"!  This works because (at least in present
Haskell implementations) IO's (>>=) is not strict in its first argument.

Noticing that this function has been implemented (slightly wrongly) for
NHC in base, so I mention this odd suggestion.

Isaac