[Haskell-cafe] trace function

Neil Mitchell ndmitchell at gmail.com
Thu Jul 20 06:09:15 EDT 2006


Either one of these will work:

main = do
 putStrLn "xxx"
 x <- return (trace "yyy" ())
 x `seq` putStrLn "zzz"

main = do
 putStrLn "xxx"
 trace "yyy" (return ())
 putStrLn "zzz"

This works fine, the problem is that trace is defined to output the
first parameter before returning the second. In the case of return ()
the () is never evaluated, hence the item is never generated, and the
trace is not fired. Adding a seq to the result gets the trace going.

This just shows how fragile trace is! However, if you use it in a real
situation, rather than just a play one like this, it will probably
work for you.



More information about the Haskell-Cafe mailing list