aboutsummaryrefslogtreecommitdiff
path: root/catalog.ml
diff options
context:
space:
mode:
Diffstat (limited to 'catalog.ml')
-rwxr-xr-xcatalog.ml21
1 files changed, 18 insertions, 3 deletions
diff --git a/catalog.ml b/catalog.ml
index 67ec69d..e4cd34b 100755
--- a/catalog.ml
+++ b/catalog.ml
@@ -7,6 +7,8 @@ module type DATA_SIG = sig
val compare_typ: 'a typ -> 'b typ -> ('a, 'b) T.cmp
+ val repr: Format.formatter -> 'a typ -> unit
+
end
(** We cannot update an existing function. Any [registerX] function will raise
@@ -30,6 +32,12 @@ module Make(Data:DATA_SIG) = struct
| T2: 'a Data.typ * 'b Data.typ -> ('a * 'b) t_function sig_typ
| T3: 'a Data.typ * 'b Data.typ * 'c Data.typ -> ('a * 'b * 'c) t_function sig_typ
+
+ let repr: type a. Format.formatter -> a sig_typ -> unit = fun formatter -> function
+ | T1 t -> Format.fprintf formatter "(%a)" Data.repr t
+ | T2 (t1, t2) -> Format.fprintf formatter "(%a,%a)" Data.repr t1 Data.repr t2
+ | T3 (t1, t2, t3) -> Format.fprintf formatter "(%a,%a,%a)" Data.repr t1 Data.repr t2 Data.repr t3
+
module ComparableSignature = struct
type 'a t = string * 'a sig_typ
@@ -73,17 +81,22 @@ module Make(Data:DATA_SIG) = struct
end
+
+ let repr : type a. Format.formatter -> a t -> unit = begin fun formatter (str, typ) ->
+ Format.fprintf formatter "%s:%a"
+ str
+ repr typ
+ end
+
end
- module Catalog = Map.Make(String)
module Functions = Splay.Make(ComparableSignature)
-
(* This is the map which contains all the registered functions.
Each name is binded with another map with contains the function for each
signature.
*)
- type t = Functions.tree
+ type t = Functions.t
let empty = Functions.empty
@@ -107,4 +120,6 @@ module Make(Data:DATA_SIG) = struct
Functions.find ((String.uppercase_ascii name), signature) t
end
+ let repr = Functions.repr
+
end