[Haskell-beginners] Printing the result of a function evaluation

Travis Erdman traviserdman at yahoo.com
Mon Mar 8 18:57:19 EST 2010


Why oh why doesn't this work as I expect, and what is the simplest fix?  

speedTest 4 = 44

time :: (Show t) => IO t -> IO t
time a = do
    start <- getCPUTime
    v <- a
    end   <- getCPUTime
    let diff = (fromIntegral (end - start)) / (10^12)
    print v -- WHY DOESNT THIS WORK?  ALWAYS PRINTS () ....
    printf "Computation time: %0.3f sec\n" (diff :: Double)
    return v

main :: IO ()
main = do
    args <- getArgs
    time $ speedTest (read $ head args) `seq` return ()



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100308/c83ea593/attachment.html


More information about the Beginners mailing list