Commits

Yit Phang Khoo  committed 9333712

Separate the basic parts of SAList.Make into another functor SAList.MakeBasic.

  • Participants
  • Parent commits 7489a53

Comments (0)

Files changed (2)

File Source/Adapton/SAList.ml

     end
     include T
 
+    (** Output module types of {!SAList.MakeBasic}. *)
+    module type BasicS = Signatures.SAListType.BasicS
+
+    (** Output module types of {!SAList.Make}. *)
     module type S = Signatures.SAListType.S
 
-    (** Functor to make various list constructors, updaters, and combinators for self-adjusting lists of a specific type. *)
-    module Make (R : Hashtbl.SeededHashedType)
-            : Signatures.SAListType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t salist and type t' = R.t salist' = struct
-
+    (** Helper functor to make basic list constructors, updaters, and combinators for self-adjusting lists of a specific type. *)
+    module MakeBasic (R : Hashtbl.SeededHashedType)
+            : BasicS with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t salist and type t' = R.t salist' = struct
         module L = M.Make (struct
             type t = R.t salist'
             let hash seed = function
             end
 
         (** Create memoizing constructor and updater that map a self-adjusting list with a mapping function. *)
-        let memo_map (type a) (type b) (module L : Signatures.SAListType.S with type sa = sa and type data = a and type t = b) f =
+        let memo_map (type a) (type b) (module L : Signatures.SAListType.BasicS with type sa = sa and type data = a and type t = b) f =
             memo (module L) begin fun map xs -> match L.force xs with
                 | `Cons ( x, xs ) -> `Cons ( f x, map xs )
                 | `Nil -> `Nil
             end
 
         (** Create memoizing constructor and updater that scan (fold over prefixes of) a self-adjusting list with an scanning function. *)
-        let memo_scan (type a) (type b) (module L : Signatures.SAListType.S with type sa = sa and type data = a and type t = b) f =
+        let memo_scan (type a) (type b) (module L : Signatures.SAListType.BasicS with type sa = sa and type data = a and type t = b) f =
             memo2 (module L) (module R) begin fun scan xs acc -> match L.force xs with
                 | `Cons ( x, xs ) -> let acc = f x acc in `Cons ( acc, scan xs acc )
                 | `Nil -> `Nil
             end
+    end
+
+
+    (** Functor to make various list constructors, updaters, and combinators for self-adjusting lists of a specific type. *)
+    module Make (R : Hashtbl.SeededHashedType)
+            : S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t salist and type t' = R.t salist' = struct
+        module L = MakeBasic (R)
+        include L
 
         (** Output type of memo_partition (a lazy pair of lists). *)
         module PartitionType = M.Make (Types.Tuple2 (L) (L))

File Source/Adapton/Signatures.ml

 
 (** Output module types of modules for self-adjusting lists. *)
 module rec SAListType : sig
-    (** Module type for self-adjusting lists for a specific type. *)
-    module type S = sig
+    (** Module type for self-adjusting lists for a specific type containing basic types and operations. *)
+    module type BasicS = sig
         type sa
         type 'a thunk
         type data
         val memo_append : (t -> t -> t) * (t -> t -> t -> unit)
         val memo_filter : (data -> bool) -> (t -> t) * (t -> t -> unit)
         val memo_map
-            : (module SAListType.S with type sa = sa and type data = 'a and type t = 'b) -> ('a -> data) -> ('b -> t) * (t -> 'b -> unit)
+            : (module SAListType.BasicS with type sa = sa and type data = 'a and type t = 'b)
+                -> ('a -> data) -> ('b -> t) * (t -> 'b -> unit)
         val memo_scan
-            : (module SAListType.S with type sa = sa and type data = 'a and type t = 'b) -> ('a -> data -> data) -> ('b -> data -> t) * (t -> 'b -> data -> unit)
+            : (module SAListType.BasicS with type sa = sa and type data = 'a and type t = 'b)
+                -> ('a -> data -> data) -> ('b -> data -> t) * (t -> 'b -> data -> unit)
+    end
+
+    (** Module type for self-adjusting lists for a specific type. *)
+    module type S = sig
+        include BasicS
         module PartitionType : SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = t * t and type t = (t * t) thunk
         val split_partition : PartitionType.t -> t * t
         val memo_partition_with_key
     val take : 'a salist -> int -> 'a list
     val hd : 'a salist -> 'a
     val tl : 'a salist -> 'a salist
+    module type BasicS = SAListType.BasicS
     module type S = SAListType.S
+    module MakeBasic (R : Hashtbl.SeededHashedType)
+        : BasicS with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t salist and type t' = R.t salist'
     module Make (R : Hashtbl.SeededHashedType)
         : S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t salist and type t' = R.t salist'
 end