[PRL] laziness

Richard C. Cobbe cobbe at ccs.neu.edu
Wed Jun 23 06:23:11 EDT 2004


Lo, on Tuesday, June 22, Johan did write:

> However, there is (IMHO) a a big win in clarity / expressiveness. "if" 
> becomes a function, not syntax...

So why is this a big win?  In Scheme, at least, if expressions look
exactly like function calls anyway; the only limitation is that I can't
treat `if' as a value.  But you'd be surprised how rarely I want to do
that anyway (as opposed, say, to wanting to treat `and' and `or' as
values).

Lo, on Wednesday, June 23, Jeffrey Palm did write:

> David A. Herman wrote:
> 
> > 2) Will it "automatically" buy me better performance?
>
> I would think delaying any computation could help your memory 
> performance, at least.  Assuming that performing a computation adds to 

Unfortunately, this is not the case, and it has to do with Johan's fold
example, quoted below.  I don't quite understand the mechanism by which
this allocates large amounts of core, and I'm too lazy (pun not
intended) to work this out now.  However, I think this is similar to a
problem that came up in a recent SRFI reference implementation of
laziness, and Joe Marshall (who should be on this list) was one of the
folks who pointed out the problem with space there.  ISTR he also
referred me to an implementation that would, in fact, not allocate
asymptotically more than a strict implementation (don't want to say
`safe-for-space', because I'm not entirely sure it is).  So I'm sure he
could explain the problem and a potential solution in some detail.

The example from Johan's original mail:

> try the following on for size:
> 
> foldl f acc []  = acc
> foldl f acc (hd:tl) = foldl f (f hd acc) tl
> 
> nice and tail-recursive. however
> 
> foldl (+) 0 [0 .. 10000000]
> 
> fails to terminate: runs out of memory.

Richard



More information about the PRL mailing list