using less stack
Jon Fairbairn
Jon.Fairbairn@cl.cam.ac.uk
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,
though.
J=F3n
-- =
J=F3n Fairbairn Jon.Fairbairn@cl.cam.ac.u=
k
31 Chalmers Road jf@cl.cam.ac.uk
Cambridge CB1 3SZ +44 1223 570179 (after 14:00 only, please!)