
Hello, Sorry for asking such a silly question: Haskell is using lazy evaluation. So, it means we should be able to declare and use a list of billions elements without any trouble. So I declare my list as follow: mylist :: [Integer] mylist = [1..1000000000] In Hugs, I type mylist to print out all the elements inside. However, after printing about 22000 elements, the system crashs & outputs: "Garbage collection fails to reclaim sufficient memory" Would you please help me with this problem? Thank you very much, Phan Dung.

Nguyen Phan Dung writes: : | mylist :: [Integer] | mylist = [1..1000000000] | | In Hugs, I type mylist to print out all the elements inside. However, | after printing about 22000 elements, the system crashs & outputs: | "Garbage collection fails to reclaim sufficient memory" The declaration of mylist is a pattern binding, not a function binding - see section 4.4.3 of the Haskell 98 report. What that means in this particular case is that the system saves the result in case you want to use it again, rather than freeing the part of the list it's already printed. Try typing [1..1000000000] at the Hugs prompt instead. Regards, Tom

On Mon, 4 Mar 2002, Tom Pledger wrote:
Nguyen Phan Dung writes: : | mylist :: [Integer] | mylist = [1..1000000000] | | In Hugs, I type mylist to print out all the elements inside. However, | after printing about 22000 elements, the system crashs & outputs: | "Garbage collection fails to reclaim sufficient memory"
The declaration of mylist is a pattern binding, not a function binding - see section 4.4.3 of the Haskell 98 report.
What that means in this particular case is that the system saves the result in case you want to use it again, rather than freeing the part of the list it's already printed.
Try typing [1..1000000000] at the Hugs prompt instead.
So would wrapping such possibly fiendish entities as [1..] with the "const" function and replacing all references to the toplevel binding with "(binding ())" make sure that the first part of the list could be thrown away and re-computed if needed? Or does one need to NOINLINE it as well? Example to make myself clear: mylist = const [1..1000000000] main = print (mylist ()) It seems like we had a discussion about something very similar to this a few months ago on some haskell.org list. Thanks, Jay Cox
participants (3)
-
Jay Cox
-
Nguyen Phan Dung
-
Tom Pledger