| |
let print_type t =
let cyclic = marker() in
begin try acyclic t
| with Cycle l -> List.iter (fun t -> (repr t).mark <- cyclic) l;
end;
let named = marker() in
let rec print k out t =
let string x = Printf.fprintf out x in
let paren p f =
if k > p then string "("; f(); if k > p then string ")" in
let t = repr t in
if t.mark > named then string "'a%d" (t.mark - named)
else
begin match desc t with
| Tvar n ->
t.mark <- marker(); string "'a%d" (t.mark - named)
| Tcon (Tint, []) ->
string "int"
| Tcon (Tarrow, [t1; t2]) when t.mark = cyclic ->
t.mark <- marker();
string "(%a -> %a as 'a%d)"
(print 1) t1 (print 1) t2 (t.mark - named);
| Tcon (Tarrow, [t1; t2]) ->
paren 0 (fun() ->
string "%a -> %a" (print 1) t1 (print 1) t2)
| Tcon (g, l) -> raise (Arity (t, t))
end in
print 0 stdout t;; |
|