[clean-list] hd (drop 1000000 [1..]) heapFull

zuurb078 at planet.nl zuurb078 at planet.nl
Mon Jul 22 17:11:43 MEST 2013


So is this desired behaviour, in the context of hd?
 

________________________________



On 19-7-2013 22:10, Pieter Koopman wrote:
> Hi Erik,
>
> there seems to be a problem with the generator.
>
> Start = hd (drop n [1..n+10]) where n = 1000000
>
> works fine. Hopefully John can explain this.

[1..] generates a list in the following way:

let
        gen_list n = [n : gen_list (n+1)]
in
        gen_list 1

Because gen_list is not strict in argument n,
a thunk is created for the expression (n+1) at runtime.
The first time this creates a thunk t0 with 1+1,
the next time a thunk t1 with t0+1, then t2 with
t1+1, ..
So after 1000000 elements, the heap contains 1000000
thunks.

The arguments of the function generated for [1..n+10] are strict,
because 1 is compared with n+10, so no increment thunks
are created.

> On 7/19/13 4:41 PM, zuurb078 at planet.nl wrote:
>> Re: [clean-list] Matrix operations
>> Start = hd (drop 1000000 [1..])
>> with standard heap (2M) leads to a heapfull message; not when I only
>> drop 1000.
>> I had expected the garbage collector to kick in so this would
>> effectively run in constant space
>> Any ideas?
>>
>>
>> _______________________________________________
>> clean-list mailing list
>> clean-list at science.ru.nl
>> http://mailman.science.ru.nl/mailman/listinfo/clean-list
>
>
>
>
> _______________________________________________
> clean-list mailing list
> clean-list at science.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/clean-list



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/clean-list/attachments/20130722/5106f988/attachment.html>


More information about the clean-list mailing list