[clean-list] Re: 'Heap Full' error

Maarten de Mol M.deMol at cs.ru.nl
Mon Feb 20 12:59:09 MET 2006


Hello lethevert,

The heap full is caused by the fully lazy way in which [0..] is computed.
Not only the constructors are computed lazily (which is a good thing
in this case), but the elements themselves as well. This causes the
n-th element of the list to be represented by:

     1 + 1 + 1 + .... + 1                           (n-1 times +)

When you select the 10.000.000th element of the list, the strictness of
+ causes a closure of 9.999.999 applications of + to be built, before the
first (1 + 1) can actually be computed. This extremely large closure causes
the heap full error.

When you use [!0..], the list becomes element-strict and the elements
are computed as the list is constructed. If you then select the n-th 
element,
you simply get the fully evaluated integer n, and thus no heap overflow.

Alternatively, when you replace [0..] with [0..10000001], the program will
also terminate normally. In this case, the continuous comparison against
the upperbound 10.000.001 enforces intermediate evaluation as well.

I hope this answers your question.

Best regards,

Maarten de Mol
(member of the 'Clean-Team') 




More information about the clean-list mailing list