[Haskell-cafe] Question regarding deepseq (Control.DeepSeq)

Ivan Miljenovic ivan.miljenovic at gmail.com
Thu Jun 24 21:25:09 EDT 2010


On 25 June 2010 11:19, Frank Moore <frankmoore at math.cornell.edu> wrote:
> Thanks for the reply.
>
> My main is now:
>
> main = do
>   let as = [1..2e7] :: [Double]
>   start <- getCurrentTime
>   let meanAs = mean as
>   let meanOver2 = meanAs `deepseq` meanAs / 2
>   end <- getCurrentTime
>   putStrLn (show (end `diffUTCTime` start))
>   start <- getCurrentTime
>   putStrLn (show meanOver2)
>   end <- getCurrentTime
>   putStrLn (show (end `diffUTCTime` start))
>
> The time is still spent on the show meanOver2 command :(

Well, yes, because the seq'ing is still happening as part of meanOver2.

The alternative is to have yet another let statement which is just
"let meanAs' = meanAs `deepSeq` meanAs" and then have "meanOver2 =
meanAs' / 2".

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list