[Haskell-cafe] trace function

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Thu Jul 20 07:35:28 EDT 2006


Alexander Vodomerov <alex at sectorb.msk.ru> wrote:

> main = do
>   putStrLn "xxx"
>   return (trace "yyy" ())
>   putStrLn "zzz"
> 
> only xxx and zzz is displayed. yyy is missing.

This is because you never demanded the value of (trace "yyy" ()), so it
was never computed.  The joys of laziness!  To force its evaluation try

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

Regards,
    Malcolm


More information about the Haskell-Cafe mailing list