
On Sat, 2010-03-13 at 21:20 +0100, legajid wrote:
Hi, my following code should show time before executing listeprem, then time after execution.
import System.Time import Control.Exception
gettime :: IO ClockTime gettime = getClockTime
main=do t1d <- gettime let t1=last (listeprem 5000)
evaluate t1
t1f <- gettime putStrLn ("Methode 1 : " ++ show t1d) putStrLn (" " ++ show t1) putStrLn (" " ++ show t1f)
Looking at the screen, t1d is displayed then, after a few seconds, t1 and t1f. But, t1d and t1f are equal. It seems like if t1d and t1f where calculated at start of procedure, before we need calculating t1 for putStrLn. How can i have t1f evaluated after t1, so i can calculate time elapsed for calculation of t1?
Thanks, Didier
Haskell calculates the expression when it needs. So let t1 = last (listeprem 5000) Means rather 't1 is expression ....' then calculate .... and save result in t1. evaluate is a nice function that forces the evaluation. Regards