<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> </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>> Hi Erik,<BR>><BR>> there seems to be a problem with the generator.<BR>><BR>> Start = hd (drop n [1..n+10]) where n = 1000000<BR>><BR>> works fine. Hopefully John can explain this.<BR><BR>[1..] generates a list in the following way:<BR><BR>let<BR> gen_list n = [n : gen_list (n+1)]<BR>in<BR> 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>> On 7/19/13 4:41 PM, zuurb078@planet.nl wrote:<BR>>> Re: [clean-list] Matrix operations<BR>>> Start = hd (drop 1000000 [1..])<BR>>> with standard heap (2M) leads to a heapfull message; not when I only<BR>>> drop 1000.<BR>>> I had expected the garbage collector to kick in so this would<BR>>> effectively run in constant space<BR>>> Any ideas?<BR>>><BR>>><BR>>> _______________________________________________<BR>>> clean-list mailing list<BR>>> clean-list@science.ru.nl<BR>>> <A href="http://mailman.science.ru.nl/mailman/listinfo/clean-list">http://mailman.science.ru.nl/mailman/listinfo/clean-list</A><BR>><BR>><BR>><BR>><BR>> _______________________________________________<BR>> clean-list mailing list<BR>> clean-list@science.ru.nl<BR>> <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>