Lazy lists - an implementation.

Ulf Wiger etxuwig@REDACTED
Wed Oct 18 10:41:23 CEST 2000


On Tue, 17 Oct 2000, Richard Carlsson wrote:

>And here is my first version of a lazy lists library. Seems to work ok.
>Nothing is evaluated unless necessary. Note, though, that my
>interpretation of a lazy list is (like in the example that Tobbe gave, due
>to Phil Wadler) a fun:
>
>	LazyList :: () -> [] | [term() | LazyList]
>
>This makes things easier. The way Ulf implemented them can be seen as
>using an explicit push-back buffer for an initial number of known
>elements, but this makes programming with fully lazy lists more difficult,
>because many more cases must be handled. (In my implementation, you can
>push stuff back using e.g. `cons(H, T)' when necessary.) Also, in Ulfs
>current implementation, either a list is empty or the first element has
>been computed. (This could be fixed, though.)

>From one perspective, it does make things easier. However, when we 
(at AXD 301) landed on the definition 

  LazyList :: list() | [term() | fun()]

it was partly because we wanted to stay as close to today's list
syntax as possible - remember *our* objective to minimize the amount
of code we have to rewrite, when switching between a list
representation and a table representation.

It's not immediately obvious to me how this can be achieved when a
lazy list is "merely" a fun.

I will do some thinking about this.

/Uffe
-- 
Ulf Wiger                                    tfn: +46  8 719 81 95
Strategic Product & System Management        mob: +46 70 519 81 95
Ericsson Telecom AB,              Datacom Networks and IP Services
Varuvägen 9, Älvsjö,                    S-126 25 Stockholm, Sweden




More information about the erlang-questions mailing list