aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hashcons.ml19
-rw-r--r--lib/hashcons.mli6
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/hashcons.ml b/lib/hashcons.ml
index db502c90c..b33a20058 100644
--- a/lib/hashcons.ml
+++ b/lib/hashcons.ml
@@ -126,6 +126,25 @@ let register_hcons h u =
(* Basic hashcons modules for string and obj. Integers do not need be
hashconsed. *)
+(* list *)
+module type SomeData = sig type t end
+module Hlist (D:SomeData) =
+ Make(
+ struct
+ type t = D.t list
+ type u = (t -> t) * (D.t -> D.t)
+ let hashcons (hrec,hdata) = function
+ | x :: l -> hdata x :: hrec l
+ | l -> l
+ let equal l1 l2 =
+ l1 == l2 ||
+ match l1, l2 with
+ | [], [] -> true
+ | x1::l1, x2::l2 -> x1==x2 && l1==l2
+ | _ -> false
+ let hash = Hashtbl.hash
+ end)
+
(* string *)
module Hstring = Make(
struct
diff --git a/lib/hashcons.mli b/lib/hashcons.mli
index 2f86174b2..ae7d6b9d9 100644
--- a/lib/hashcons.mli
+++ b/lib/hashcons.mli
@@ -91,5 +91,11 @@ val recursive2_hcons :
module Hstring : (S with type t = string and type u = unit)
(** Hashconsing of strings. *)
+module type SomeData = sig type t end
+
+module Hlist (D:SomeData) :
+ (S with type t = D.t list and type u = (D.t list -> D.t list)*(D.t->D.t))
+(** Hashconsing of lists. *)
+
module Hobj : (S with type t = Obj.t and type u = (Obj.t -> Obj.t) * unit)
(** Hashconsing of OCaml values. *)