stream
Last time: manipulating infinite data structures in lazyCaml
…
let rec nats n = n::(nats (n+1))
let rec trues = true::trues
Let’s write hd_s
, tl_s
, take_s
, nat_s
, squares_s
, map_s
…
match s with End -> End
| Cons(h,t) -> if (p h) then Cons(h, fun () -> filter_s p (t ()))
else filter_s p (t ())
Technically, streams simulate normal order evaluation (call-by-name) but not lazy evaluation, since there is no sharing…
cs2041.org