Lazy evaluation alternative

Jerzy Karczmarczuk karczma@info.unicaen.fr
Fri, 24 Jan 2003 13:51:57 +0100


Chris Clearwater wrote:
> It seems to
> me you could get some of the desired effects of lazy evaluation by using
> continuation passing style in code. For example, take this psuedo-code
> using CPS to represent an infinite data type.
> 
> Using non-CPS this would be something like:
> ones = 1 : ones
> 
> using strict evaluation this would lead to an infinite loop.
> 
> However using CPS this could be represented as:
> ones c = c (1 : ones)
> 
> where c is the continuation.
> 
> This would not infinite loop as ones is still waiting for the
> continuation argument. Another example:
> 
> natural n c = c (n : natural n+1)


Hey, Maestro, why don't you check before posting, hm? What is the type
of ones? I am afraid you will get a nasty surprise...

... BTW, are you sure there aren't any missing parentheses in the
def. of natural? (But they won't help anyway...)


Jerzy Karczmarczuk