Re: [Haskell-cafe] trace function
Alexander Vodomerov <[EMAIL PROTECTED]> 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] trace function
Hi, 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. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] trace function
Alexander Vodomerov wrote: > import Debug.Trace > > main = do > putStrLn "xxx" > return (trace "yyy" ()) > putStrLn "zzz" > > only xxx and zzz is displayed. yyy is missing. > Why trace is not working? Nothing uses the value of (trace "yyy" ()), so it is never evaluated. Try this instead, which uses the value for a pattern match: () <- return (trace "yyy" ()) Or this, which makes the trace part of the sequence of IO actions: trace "yyy" (return ()) HTH, Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] trace function
Hello! The function trace is supposed to write debug messages to console. However, when I trying to run the following program import Debug.Trace main = do putStrLn "xxx" return (trace "yyy" ()) putStrLn "zzz" only xxx and zzz is displayed. yyy is missing. Why trace is not working? PS. GHC-6.4.2, Debian Linux on x86. With best regards, Alexander. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe