aboutsummaryrefslogtreecommitdiff
path: root/lib/hashcons.mli
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2014-12-17 19:12:11 +0100
committerPierre-Marie Pédrot2014-12-17 19:38:36 +0100
commit6b2ec938010c50dae3ec6c87ff8ea7f2a4012b92 (patch)
treebf02ac37d72cdfe17c765796632464ee42a8de58 /lib/hashcons.mli
parente4ac6f91e8d95a168cdaeaec72cf761b7b6da4b7 (diff)
Ensuring the good invariants of hashcons table generation in the API.
Diffstat (limited to 'lib/hashcons.mli')
-rw-r--r--lib/hashcons.mli26
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/hashcons.mli b/lib/hashcons.mli
index cf3a09af4a..5bf0a40301 100644
--- a/lib/hashcons.mli
+++ b/lib/hashcons.mli
@@ -21,7 +21,7 @@ module type HashconsedType =
enhance efficiency of equality tests.
In order to ensure canonicality, we need a way to remember the element
- associated to a class of equivalence; this is done using a hidden state
+ associated to a class of equivalence; this is done using the table type
generated by the [Make] functor.
*)
@@ -50,14 +50,12 @@ module type S =
(** Type of objects to hashcons. *)
type u
(** Type of hashcons functions for the sub-structures contained in [t]. *)
- val generate : unit -> (u -> t -> t)
- (** This has the side-effect of creating (internally) a hashtable of the
- hashconsed objects. The result is a function taking the sub-hashcons
- functions and an object, and hashconsing it. It does not really make sense
- to call [generate] with different sub-hcons functions. That's why we use the
- wrappers [simple_hcons], [recursive_hcons], ... The latter just take as
- argument the sub-hcons functions (the tables are created at that moment),
- and returns the hcons function for [t]. *)
+ type table
+ (** Type of hashconsing tables *)
+ val generate : u -> table
+ (** This create a hashtable of the hashconsed objects. *)
+ val hcons : table -> t -> t
+ (** Perform the hashconsing of the given object within the table. *)
end
module Make (X : HashconsedType) : (S with type t = X.t and type u = X.u)
@@ -68,19 +66,13 @@ module Make (X : HashconsedType) : (S with type t = X.t and type u = X.u)
(** These are intended to be used together with instances of the [Make]
functor. *)
-val simple_hcons : (unit -> 'u -> 't -> 't) -> ('u -> 't -> 't)
+val simple_hcons : ('u -> 'tab) -> ('tab -> 't -> 't) -> 'u -> 't -> 't
(** [simple_hcons f sub obj] creates a new table each time it is applied to any
sub-hash function [sub]. *)
-val recursive_hcons : (unit -> ('t -> 't) * 'u -> 't -> 't) -> ('u -> 't -> 't)
+val recursive_hcons : (('t -> 't) * 'u -> 'tab) -> ('tab -> 't -> 't) -> ('u -> 't -> 't)
(** As [simple_hcons] but intended to be used with well-founded data structures. *)
-val recursive2_hcons :
- (unit -> ('t1 -> 't1) * ('t2 -> 't2) * 'u1 -> 't1 -> 't1) ->
- (unit -> ('t1 -> 't1) * ('t2 -> 't2) * 'u2 -> 't2 -> 't2) ->
- 'u1 -> 'u2 -> ('t1 -> 't1) * ('t2 -> 't2)
-(** As [recursive_hcons] but with two mutually recursive structures. *)
-
(** {6 Hashconsing of usual structures} *)
module type HashedType = sig type t val hash : t -> int end