From c892f8cab37c0a89f6975e6a14bebad4d86156bd Mon Sep 17 00:00:00 2001 From: Pierre-Marie Pédrot Date: Thu, 3 Jul 2014 17:45:06 +0200 Subject: Adding a coiterator to IStream. --- lib/iStream.ml | 6 ++++++ lib/iStream.mli | 3 +++ 2 files changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/iStream.ml b/lib/iStream.ml index da54d9f7b8..36b9c43ad0 100644 --- a/lib/iStream.ml +++ b/lib/iStream.ml @@ -20,6 +20,12 @@ let cons x s = Lazy.lazy_from_val (Cons (x, s)) let thunk = Lazy.lazy_from_fun +let rec make_node f s = match f s with +| Nil -> Nil +| Cons (x, s) -> Cons (x, make f s) + +and make f s = lazy (make_node f s) + let rec force s = match Lazy.force s with | Nil -> () | Cons (_, s) -> force s diff --git a/lib/iStream.mli b/lib/iStream.mli index 61967f49e4..a059570107 100644 --- a/lib/iStream.mli +++ b/lib/iStream.mli @@ -31,6 +31,9 @@ val cons : 'a -> 'a t -> 'a t val thunk : (unit -> ('a,'a t) u) -> 'a t (** Internalize the lazyness of a stream. *) +val make : ('a -> ('b, 'a) u) -> 'a -> 'b t +(** Coiteration constructor. *) + (** {6 Destructors} *) val is_empty : 'a t -> bool -- cgit v1.2.3