camlspotter avatar camlspotter committed 2711ef4

moved Lazylist to Spotlib.Stream

Comments (0)

Files changed (6)

    mtypes
    position
    result
-   lazylist
    stream_intf
    stream
    sstring

lib/lazylist.ml

-open Lazy
-
-type 'a zlist = 'a desc lazy_t
-
-and 'a desc =
-  | Cons of 'a * 'a zlist
-  | Null
-
-let null = lazy_from_val Null
-
-let desc = force
-let peek = function
-  | lazy Null -> None
-  | lazy Cons (v, t') -> Some (v, t')
-
-let is_null = function
-  | lazy Null -> true
-  | _ -> false
-
-let to_list t = 
-  let rec to_list st = function
-    | lazy Null -> List.rev st
-    | lazy Cons (elem, t) -> to_list (elem :: st) t
-  in
-  to_list [] t
-  
-let rec iter f = function
-  | lazy Null -> ()
-  | lazy Cons (elem, t) -> f elem; iter f t
-
-let rec fold_right f lst st = match lst with
-  | lazy Null -> st
-  | lazy Cons (v, lst') -> f v (fold_right f lst' st)
-
-let rec map f lst = lazy (match lst with
-  | lazy Null -> Null
-  | lazy Cons (v, lst') -> Cons (f v, map f lst'))
-
-(* [t2] must be a postfix of [t1] otherwise, it loops forever *)
-let rev_between t1 t2 =
-  let rec loop st t =
-    if t == t2 then st (* CR jfuruse: we cannot always use pointer eq *)
-    else 
-      match t with
-      | lazy Cons (elem, t') -> loop (elem::st) t'
-      | lazy Null -> st
-  in
-  loop [] t1
-
-let between t1 t2 = List.rev (rev_between t1 t2)
-

lib/lazylist.mli

-(** This is a lazy list basically, but its elements and nil can have extra information. *)
-
-type 'a zlist = 'a desc lazy_t
-
-and 'a desc = 
-  | Cons of 'a * 'a zlist
-  | Null 
-
-(** Constructor functions *)
-val null : 'a zlist
-
-(** Destructors *)
-val desc : 'a zlist -> 'a desc
-val peek : 'a zlist -> ('a * 'a zlist) option
-val is_null : 'a zlist -> bool
-
-val to_list : 'a zlist -> 'a list
-
-val iter : ('a -> unit) -> 'a zlist -> unit
-val fold_right : ('a -> 'b -> 'b) -> 'a zlist -> 'b -> 'b
-val map : ('a -> 'b) -> 'a zlist -> 'b zlist
-
-val rev_between : 'a zlist -> 'a zlist -> 'a list
-val between : 'a zlist -> 'a zlist -> 'a list
 open Stream_intf
 
+(** Import the constructors *)
+type 'a desc = 'a Spotlib.Stream.desc = 
+  | Cons of 'a * 'a desc lazy_t
+  | Null
+
 module Make(P : Base) = struct
 
-  open Lazylist
+  open Spotlib.Stream
   include P
 
-  type desc = (Elem.t option * Attr.t) Lazylist.desc
-  type t = (Elem.t option * Attr.t) zlist (* None means EOS *)
+  type desc = (Elem.t option * Attr.t) Spotlib.Stream.desc
+  type t = (Elem.t option * Attr.t) Spotlib.Stream.t (* None means EOS *)
 
-  let cons_desc e attr v = Lazylist.Cons ((Some e,attr), v)
-  let null_desc attr = Lazylist.Cons ((None, attr), Lazylist.null)
+  let cons_desc e attr v = Cons ((Some e,attr), v)
+  let null_desc attr = Cons ((None, attr), Spotlib.Stream.null)
   let null attr = Lazy.lazy_from_val (null_desc attr)
 
-  let desc = desc
   let peek = function
     | lazy Cons ((Some elem, _), t') -> Some (elem, t')
     | _ -> None
 (** Stream module. See Stream_intf for more details *)
 open Stream_intf
 
+(** Import the constructors *)
+type 'a desc = 'a Spotlib.Stream.desc = 
+  | Cons of 'a * 'a desc lazy_t
+  | Null
+
 module Make (Base : Base) : S 
   with type Pos.t  = Base.Pos.t
   and  type Elem.t = Base.Elem.t

lib/stream_intf.ml

 (** Stream interface *)
 
-(* open Spotlib.Spot *)
-open Lazylist
-
 (** Minimum specification to create a stream *)
 module type Base = sig
 
   module Pos : Position.S
+  (** Position of the stream. 
+      Position is a part of the stream attribute defined below. *)
 
   module Attr : sig
     type t
     val position : t -> Pos.t
   end 
-  (** Module for stream positions *)
+  (** Stream attribute, available for each stream element and the null.
+      The position of the stream must be obtained from [Attr.t].
+  *)
 
   module Elem : sig
     type t
 
   type desc
   type t = desc Lazy.t
+  (** Stream type [t] is lazy by nature, and [desc] is its forced form. *)
 
   val null : Attr.t -> t
   (** Create a null stream *)
 
   val null_desc : Attr.t -> desc
   val cons_desc : Elem.t -> Attr.t -> t -> desc
-  (** Create a null/cons cell desc. *)
+  (** Create a null/cons cell desc, useful for stream creation *)
 
   (** Destructors *)
-  val desc : t -> desc
   val peek : t -> (Elem.t * t) option
 
   val is_null : t -> bool
 
   val attr : t -> Attr.t
   val position : t -> Pos.t
-  (** Position of the head element/null *)
+  (** Attribute and Position of the head element or null *)
 
   val to_list : t -> Elem.t list
-
   val iter : (Elem.t -> unit) -> t -> unit
   val fold_right : (Elem.t -> 'a -> 'a) -> t -> 'a -> 'a
-  val map : (Elem.t -> 'a) -> t -> 'a zlist
+  val map : (Elem.t -> 'a) -> t -> 'a Spotlib.Stream.t
   (** Iteration, folding and map *)
 
   val rev_between : t -> t -> Elem.t list
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.