On Fri, Jan 24, 2003 at 01:51:57PM +0100, Jerzy Karczmarczuk wrote:
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...
Check what, the type? Or are you refering to the double posting? My first message got rejected as I was not a member of the list so I subscribed and reposted. It seems the moderator put it through anyways. It seems the type would recursive? Is it that a problem? Enlighten me? :)
... BTW, are you sure there aren't any missing parentheses in the def. of natural? (But they won't help anyway...)
Yes I am. But the + should be in CPS form anyways to be perfectly correct, so: natural n c = (+) n 1 (\m -> c n : (natural m))
Jerzy Karczmarczuk