[Haskell-cafe] Can't prevent memoizing in simple code

Yves Parès yves.pares at gmail.com
Wed May 16 18:08:43 CEST 2012


The buffer http://hpaste.org/68595 presents a simple code I tried to
profile.
I spotted what I strongly think to be an abusive memoization. The problem
is that I don't see how to (simply) get rid of it.
Compiled with -O2, it consumes 130MB of memory, however lines A and B
executed separately consume each only 1MB.

The infinite list (l 1), whatever I do, keeps being shared between lines A
and B.
I tried to wrap it in a function, as you can see, I also tried to make it
explicitely polymorphic (bypassing monomorphic restriction), nothing solves
it, GHC is just to good at memoizing.

NB: When compiled without optimisations, the sharing does not happen (side
note: but then lack of strictness analysis -- which is what I was testing
at the first place -- makes line A (call to suminit2) consume a lot of
memory, but this is normal).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120516/5fc58a75/attachment.htm>


More information about the Haskell-Cafe mailing list