
Michael Shulman wrote:
The GHC documentation says that (evaluate a) is not the same as (a `seq` return a). Can someone explain the difference to me, or point me to a place where it is explained?
(evaluate a) is "weaker" than (a `seq` return a). (a `seq` return a) is always _|_ whereas (evaluate a) is not _|_, but does throw an exception when executed. The appended code shows the differences. Regards, apfelmus import Prelude hiding (return,catch) import qualified Control.Monad as M import Control.Exception a = undefined :: () return = M.return :: a -> IO a e 0 = return a e 1 = a `seq` return a e 2 = evaluate a t x = e x >> return () -- t 0 == return () -- t 1 == throwIO something -- t 2 == throwIO something -- to check this, evaluate the expressions -- (t x >>= print) and (t x `seq` ()) u x = e x `seq` return () -- u 0 == return () -- u 1 == undefined -- u 2 == return () -- to check this, type (u x >>= print) into hugs/ghci v x = catch (e x) (\_ -> return ()) >>= print -- v 0 == throwIO something -- v 1 == print () -- v 2 == print ()