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

Anthony Cowley acowley at gmail.com
Wed May 16 18:19:00 CEST 2012

On May 16, 2012, at 12:08 PM, Yves Parès wrote:

> 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.

Adding a {-# NOINLINE l #-} annotation helps here. Syntactically, it must be located somewhere a type signature for l would also be valid.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120516/dcc87d30/attachment.htm>

More information about the Haskell-Cafe mailing list