Lazy Evaluation

Tom Pledger
Mon, 4 Mar 2002 16:04:54 +1300

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.