
8 Feb
2010
8 Feb
'10
5:30 p.m.
Am Montag 08 Februar 2010 22:58:03 schrieb Matthew Phillips:
P.S.
Daniel:
[*] classic example: why will
average xs = sum / len where (sum,len) = foldl' accum (0,0) xs accum (sm,ln) x = (sm+x,ln+1)
cause a stack overflow for long lists?
You gave a strong hint before this, so I'd guess it's due to the lazy tuple creation in "accum"?
Well, the tuples are forced, so in that sense, tuple creation is not lazy. But the components of the tuple are *not* forced, so they become large thunks and in that sense, tuple creation is lazy and that's indeed the cause of the stack overflow. I think you get full marks for this :)