From 3bdff980eaf72ea8be3886e8b4463a45cf4e7dc9 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 2 Nov 2017 13:34:37 +0100 Subject: Add a representation for the splay tree --- catalog.ml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'catalog.ml') 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 -- cgit v1.2.3