[Haskell-cafe] Is there any way to prevent a computation from being shared?

Petr Prokhorenkov prokhorenkov at gmail.com
Sat Nov 13 11:55:52 EST 2010

I've came upon very a strange situation with memory consumption. The
smallest test case I've been able to come up with is the following:

import Data.List

wtf d = head . dropWhile (< 10^100) . map (*d) $ enumFrom 2

main = do
    print $ wtf 1
    print $ wtf 2 -- Everything is ok without this line

Expected result is that program runs in constant space. What really
happening is that the program consumes memory until killed.
If second call to wtf is removed, memory usage stays constant while the
program is working.

The problem is in that list returned from enumFrom is being saved between
calls to wtf.

Is there any way to overcome this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101115/e6f7c74e/attachment.html

More information about the Haskell-Cafe mailing list