aboutsummaryrefslogtreecommitdiff
path: root/lib/pp.ml
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2015-12-05 13:43:07 +0100
committerPierre-Marie Pédrot2015-12-05 13:52:18 +0100
commit126a3c998c62bfd9f9b570f12b2e29576dd94cdd (patch)
treeab612a3f64d22162f2a7836cf99d963888923bff /lib/pp.ml
parent895d34a264d9d90adfe4f0618c3bb0663dc01615 (diff)
Factorizing unsafe code by relying on the new Dyn module.
Diffstat (limited to 'lib/pp.ml')
-rw-r--r--lib/pp.ml29
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/pp.ml b/lib/pp.ml
index 146d3562dd..a1913c98f7 100644
--- a/lib/pp.ml
+++ b/lib/pp.ml
@@ -51,25 +51,18 @@ sig
val prj : t -> 'a key -> 'a option
end =
struct
- (** See module {Dyn} for more details. *)
- type t = int * Obj.t
-
- type 'a key = int
-
- let dyntab = ref (Int.Map.empty : string Int.Map.t)
-
- let create (s : string) =
- let hash = Hashtbl.hash s in
- let () = assert (not (Int.Map.mem hash !dyntab)) in
- let () = dyntab := Int.Map.add hash s !dyntab in
- hash
-
- let inj x h = (h, Obj.repr x)
-
- let prj (nh, rv) h =
- if Int.equal h nh then Some (Obj.magic rv)
- else None
+module Dyn = Dyn.Make(struct end)
+
+type t = Dyn.t
+type 'a key = 'a Dyn.tag
+let create = Dyn.create
+let inj x k = Dyn.Dyn (k, x)
+let prj : type a. t -> a key -> a option = fun dyn k ->
+ let Dyn.Dyn (k', x) = dyn in
+ match Dyn.eq k k' with
+ | None -> None
+ | Some CSig.Refl -> Some x
end