using less stack

Jon Fairbairn
Wed, 20 Mar 2002 10:31:28 +0000

> Thanks for all the advice. In the end, I couldn't make $! work for me =

> (it always seems to be harder than I think it will be to use it, and $!=

> and deepSeq makes my code run slowly). =


> But a continuation passing style foldl worked wonderfully.

As Jay Cox pointed out by email, my answer was rot because I
had confused foldl and foldr

> I now have:
> =

>  > cpsfold f a [] =3D a
>  > cpsfold f a (x:xs) =3D f x a (\y -> cpsfold f y xs)
> =

> and f takes a continuation, Bob's my uncle, and I have a program that =

> runs quickly in constant space!

Good.  I'm curious to know from other readers whether
continuations like this are the only way of solving it,


-- =

J=F3n Fairbairn                       
31 Chalmers Road                               
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)