On Tuesday 15 February 2011 22:20:06, Claude Heiland-Allen wrote:
>
> Compare with the heap profile graph output from this short program which
> uses a horrible data-dependency hack to force recomputation:
>
> main = do
>    print $ length
>      [(x,y) | x <- [(1 :: Int) .. 10000], y <- [(1 :: Int) .. 10000]]
>    print $ length
>      [(x,y) | x <- [(1 :: Int) .. 10000], y <- [x+1-x .. 10000]]
>
> The heap profile graph looks a little like this:
>
> ########
> ########
> ########
> ########
> ########_______
>
> (Tested with ghc 6.12.3 -O2 on linux x86_64)
>

Yup, confirmed with 6.12.3 and 7.0.1 on x86 linux (again behaves 
differently with -fno-full-laziness).
Not only does the second use less memory, it is also faster (something 
around 10%).
Thanks for the nice example.


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to