<HTML dir=ltr><HEAD><TITLE>Re: [clean-list] hd (drop 1000000 [1..]) heapFull</TITLE>
<META content="text/html; charset=unicode" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16484"></HEAD>
<BODY>
<DIV dir=ltr id=idOWAReplyText70269>
<DIV dir=ltr><FONT color=#000000 size=2 face=Arial>So is this desired behaviour, in the context of hd?</FONT></DIV>
<DIV dir=ltr>&nbsp;</DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<BR></DIV>
<DIV>
<P><FONT size=2>On 19-7-2013 22:10, Pieter Koopman wrote:<BR>&gt; Hi Erik,<BR>&gt;<BR>&gt; there seems to be a problem with the generator.<BR>&gt;<BR>&gt; Start = hd (drop n [1..n+10]) where n = 1000000<BR>&gt;<BR>&gt; works fine. Hopefully John can explain this.<BR><BR>[1..] generates a list in the following way:<BR><BR>let<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gen_list n = [n : gen_list (n+1)]<BR>in<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gen_list 1<BR><BR>Because gen_list is not strict in argument n,<BR>a thunk is created for the expression (n+1) at runtime.<BR>The first time this creates a thunk t0 with 1+1,<BR>the next time a thunk t1 with t0+1, then t2 with<BR>t1+1, ..<BR>So after 1000000 elements, the heap contains 1000000<BR>thunks.<BR><BR>The arguments of the function generated for [1..n+10] are strict,<BR>because 1 is compared with n+10, so no increment thunks<BR>are created.<BR><BR>&gt; On 7/19/13 4:41 PM, zuurb078@planet.nl wrote:<BR>&gt;&gt; Re: [clean-list] Matrix operations<BR>&gt;&gt; Start = hd (drop 1000000 [1..])<BR>&gt;&gt; with standard heap (2M) leads to a heapfull message; not when I only<BR>&gt;&gt; drop 1000.<BR>&gt;&gt; I had expected the garbage collector to kick in so this would<BR>&gt;&gt; effectively run in constant space<BR>&gt;&gt; Any ideas?<BR>&gt;&gt;<BR>&gt;&gt;<BR>&gt;&gt; _______________________________________________<BR>&gt;&gt; clean-list mailing list<BR>&gt;&gt; clean-list@science.ru.nl<BR>&gt;&gt; <A href="http://mailman.science.ru.nl/mailman/listinfo/clean-list">http://mailman.science.ru.nl/mailman/listinfo/clean-list</A><BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt; _______________________________________________<BR>&gt; clean-list mailing list<BR>&gt; clean-list@science.ru.nl<BR>&gt; <A href="http://mailman.science.ru.nl/mailman/listinfo/clean-list">http://mailman.science.ru.nl/mailman/listinfo/clean-list</A><BR><BR></FONT></P></DIV></BODY></HTML>