[Haskell-cafe] Spelling checker exercise
Daniel Fischer
daniel.is.fischer at web.de
Mon Feb 8 17:30:07 EST 2010
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 :)
More information about the Haskell-Cafe
mailing list