Yit Phang Khoo avatar Yit Phang Khoo committed 03451f9

Add type constraints on "'a thunk" and an new abstract type "sa" to constrain SAList operations to self-adjusting values of the same type, yet allow "force" to be generically used when possible.

The abstract type "sa" is used to constrain SAList operations taking packages (first-class modules) as arguments, since package types do not support constraints on parameterized types.

Comments (0)

Files changed (8)

Source/Adapton/LazySABidi.ml

 
 (** Types and operations common to lazy self-adjusting values containing any type. *)
 module T = struct
+    (** Abstract type identifying this module for self-adjusting values. *)
+    type sa
+
     module rec TT : sig
         (** Lazy self-adjusting values containing ['a]. *)
         type 'a thunk = { (* 2 + 2 + 7 = 11 words (not including closures of receipt, repair, evaluate, and unmemo) *)
 
 
 (** Functor to make constructors and updaters for lazy self-adjusting values of a specific type. *)
-module Make (R : Hashtbl.SeededHashedType) : Signatures.SAType.S with type data = R.t and type t = R.t thunk = struct
+module Make (R : Hashtbl.SeededHashedType)
+        : Signatures.SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk = struct
     include T
 
     (** Value contained by lazy self-adjusting values for a specific type. *)

Source/Adapton/LazySABidiObject.ml

 
 (** Types and operations common to lazy self-adjusting values containing any type. *)
 module T = struct
+    (** Abstract type identifying this module for self-adjusting values. *)
+    type sa
+
     (**/**) (* auxiliary types *)
     module rec TT : sig
         type 'a state =
 
 
 (** Functor to make a constructor, a mutator, and a memoizing constructor for lazy self-adjusting values of a specific type. *)
-module Make (R : Hashtbl.SeededHashedType) : Signatures.SAType.S with type data = R.t and type t = R.t thunk = struct
+module Make (R : Hashtbl.SeededHashedType)
+        : Signatures.SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk = struct
     include T
 
     (** Value contained by lazy self-adjusting values for a specific type. *)

Source/Adapton/LazySANaive.ml

 
 (** Types and operations common to lazy self-adjusting values containing any type. *)
 module T = struct
+    (** Abstract type identifying this module for self-adjusting values. *)
+    type sa
+
     (** Lazy self-adjusting values containing ['a]. *)
     type 'a thunk = { (* 2 + 7 = 9 words (not including closures of receipt, repair, evaluate, and unmemo) *)
         id : int;
 
 
 (** Functor to make constructors and updaters for lazy self-adjusting values of a specific type. *)
-module Make (R : Hashtbl.SeededHashedType) : Signatures.SAType.S with type data = R.t and type t = R.t thunk = struct
+module Make (R : Hashtbl.SeededHashedType)
+        : Signatures.SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk = struct
     include T
 
     (** Value contained by lazy self-adjusting values for a specific type. *)

Source/Adapton/LazySAObject.ml

 
 (** Types and operations common to lazy self-adjusting values containing any type. *)
 module T = struct
+    (** Abstract type identifying this module for self-adjusting values. *)
+    type sa
+
     (**/**) (* auxiliary types *)
     type 'a state =
         | MemoValue of 'a * receipt * receipt list * (unit -> 'a) * unmemo (* 6 words *)
 
 
 (** Functor to make a constructor, a mutator, and a memoizing constructor for lazy self-adjusting values of a specific type. *)
-module Make (R : Hashtbl.SeededHashedType) : Signatures.SAType.S with type data = R.t and type t = R.t thunk = struct
+module Make (R : Hashtbl.SeededHashedType)
+        : Signatures.SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk = struct
     include T
 
     (** Value contained by lazy self-adjusting values for a specific type. *)

Source/Adapton/NonSAEager.ml

 
 (** Types and operations common to eager non-self-adjusting values containing any type. *)
 module T = struct
+    (** Abstract type identifying this module for non-self-adjusting values. *)
+    type sa
+
     (** Eager non-self-adjusting values containing ['a]. *)
     type 'a thunk = {
         id : int;
 
 
 (** Functor to make constructors and updaters for eager non-self-adjusting values of a specific type. *)
-module Make (R : Hashtbl.SeededHashedType) : Signatures.SAType.S with type data = R.t and type t = R.t thunk = struct
+module Make (R : Hashtbl.SeededHashedType)
+        : Signatures.SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk = struct
     include T
 
     (** Value contained by eager non-self-adjusting values for a specific type. *)

Source/Adapton/NonSALazy.ml

 
 (** Types and operations common to lazy non-self-adjusting values containing any type. *)
 module T = struct
+    (** Abstract type identifying this module for non-self-adjusting values. *)
+    type sa
+
     (** Lazy non-self-adjusting values containing ['a]. *)
     type 'a thunk = {
         id : int;
 
 
 (** Functor to make constructors and updaters for lazy non-self-adjusting values of a specific type. *)
-module Make (R : Hashtbl.SeededHashedType) : Signatures.SAType.S with type data = R.t and type t = R.t thunk = struct
+module Make (R : Hashtbl.SeededHashedType)
+        : Signatures.SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk = struct
     include T
 
     (** Value contained by lazy non-self-adjusting values for a specific type. *)

Source/Adapton/SAList.ml

 (** Self-adjusting lists. *)
 
 (** Functor to make self-adjusting lists, given a particular module for self-adjusting values. *)
-module Make (M : Signatures.SAType) : Signatures.SAListType with type 'a salist = [ `Cons of 'a * 'b | `Nil ] M.thunk as 'b = struct
+module Make (M : Signatures.SAType)
+        : Signatures.SAListType with type sa = M.sa and type 'a thunk = 'a M.thunk and type 'a salist = [ `Cons of 'a * 'b | `Nil ] M.thunk as 'b = struct
+
     (** Self-adjusting lists containing ['a]. *)
     type 'a salist = 'a salist' M.thunk
 
 
     (** Types and operations common to lazy self-adjusting lists containing any type. *)
     module T = struct
+        (** Abstract type identifying the given module for self-adjusting values used to create this module for self-adjusting lists. *)
+        type sa = M.sa
+
+        (** Self-adjusting values from the given module used to create this module for self-adjusting lists. *)
+        type 'a thunk = 'a M.thunk
+
         (** Compute the hash value of a self-adjusting list. *)
         let hash = M.hash
 
     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 data = R.t and type t = R.t salist and type t' = R.t salist' = struct
+    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
 
         module L = M.Make (struct
             type t = R.t salist'
             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 data = a and type t = b) f =
+        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 =
             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 data = a and type t = b) f =
+        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 =
             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

Source/Adapton/Signatures.ml

 module rec SAType : sig
     (** Module type for self-adjusting values for a specific type. *)
     module type S = sig
+        type sa
+        type 'a thunk
         type data
         type t
         val hash : int -> t -> int
 
 (** Module type for self-adjusting values. *)
 module type SAType = sig
+    type sa
     type 'a thunk
     val hash : int -> 'a thunk -> int
     val equal : 'a thunk -> 'a thunk -> bool
     val force : 'a thunk -> 'a
     val refresh : unit -> unit
-    module Make (R : Hashtbl.SeededHashedType) : SAType.S with type data = R.t and type t = R.t thunk
+    module Make (R : Hashtbl.SeededHashedType) : SAType.S with type sa = sa and type 'a thunk = 'a thunk and type data = R.t and type t = R.t thunk
 end
 
 (** {2 Self-adjusting lists} *)
 module rec SAListType : sig
     (** Module type for self-adjusting lists for a specific type. *)
     module type S = sig
+        type sa
+        type 'a thunk
         type data
         type t
         type t' = [ `Cons of data * t | `Nil ]
         val pop : t -> 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 data = 'a and type t = 'b) -> ('a -> data) -> ('b -> t) * (t -> 'b -> unit)
-        val memo_scan : (module SAListType.S with type data = 'a and type t = 'b) -> ('a -> data -> data) -> ('b -> data -> t) * (t -> 'b -> data -> unit)
-        module PartitionType : SAType.S with type data = t * t
+        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)
+        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 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 : (data -> data -> bool) -> (data -> t -> PartitionType.t) * (PartitionType.t -> data -> t -> unit)
         val memo_quicksort : (data -> data -> int) -> (t -> t) * (t -> t -> unit)
 
 (** Module type for self-adjusting lists. *)
 module type SAListType = sig
+    type sa
+    type 'a thunk
     type 'a salist
     type 'a salist' = [ `Cons of 'a * 'a salist | `Nil ]
     val hash : int -> 'a salist -> int
     val hd : 'a salist -> 'a
     val tl : 'a salist -> 'a salist
     module type S = SAListType.S
-    module Make (R : Hashtbl.SeededHashedType) : S with 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
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.