From 3af742bc49d1fbdf6c2c044abde8ec8a8b081654 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Thu, 14 Jun 2018 23:51:47 +0200 Subject: [PATCH] ugly but useful printing of sharing for bool refs --- ocaml/simple.ml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ocaml/simple.ml b/ocaml/simple.ml index f61ce5e..2cbb448 100644 --- a/ocaml/simple.ml +++ b/ocaml/simple.ml @@ -24,6 +24,29 @@ let measure_of_t = in snd ++ (aux []) ;; +let index_of x = + let rec aux n = + function + [] -> None + | x'::_ when x == x' -> Some n + | _::xs -> aux (n+1) xs + in aux 1 +;; + +let sep_of_app = + let apps = ref [] in + function + r when not !r -> " " + | r -> + let i = + match index_of r !apps with + Some i -> i + | None -> + apps := !apps @ [r]; + List.length !apps + in "," ^ string_of_int i ^ " " +;; + let string_of_t = let string_of_bvar = let bound_vars = ["x"; "y"; "z"; "w"; "q"] in @@ -35,7 +58,7 @@ let string_of_t = | A _ | L _ as t -> "(" ^ string_of_term_no_pars level t ^ ")" and string_of_term_no_pars_app level = function - | A(b,t1,t2) -> string_of_term_no_pars_app level t1 ^ (if !b then "," else " ") ^ string_of_term_w_pars level t2 + | A(b,t1,t2) -> string_of_term_no_pars_app level t1 ^ sep_of_app b ^ string_of_term_w_pars level t2 | _ as t -> string_of_term_w_pars level t and string_of_term_no_pars level = function | L(_,t) -> "λ" ^ string_of_bvar level ^ ". " ^ string_of_term_no_pars (level+1) t -- 2.39.2