72 Pretty.str "=>", print_typ tyvars NOBR ty]; |
72 Pretty.str "=>", print_typ tyvars NOBR ty]; |
73 fun constraint p1 p2 = Pretty.block [p1, Pretty.str " : ", p2]; |
73 fun constraint p1 p2 = Pretty.block [p1, Pretty.str " : ", p2]; |
74 fun print_var vars NONE = Pretty.str "_" |
74 fun print_var vars NONE = Pretty.str "_" |
75 | print_var vars (SOME v) = (Pretty.str o lookup_var vars) v; |
75 | print_var vars (SOME v) = (Pretty.str o lookup_var vars) v; |
76 fun applify_dict tyvars (Dict (_, d)) = applify_plain_dict tyvars d |
76 fun applify_dict tyvars (Dict (_, d)) = applify_plain_dict tyvars d |
77 and applify_plain_dict tyvars (Dict_Const (inst, dss)) = |
77 and applify_plain_dict tyvars (Dict_Const (inst, dictss)) = |
78 applify_dictss tyvars ((Pretty.str o deresolve o Class_Instance) inst) (map snd dss) |
78 applify_dictss tyvars ((Pretty.str o deresolve o Class_Instance) inst) (map snd dictss) |
79 | applify_plain_dict tyvars (Dict_Var { var, class, ... }) = |
79 | applify_plain_dict tyvars (Dict_Var { var, class, ... }) = |
80 Pretty.block [Pretty.str "implicitly", |
80 Pretty.block [Pretty.str "implicitly", |
81 Pretty.enclose "[" "]" [Pretty.block [(Pretty.str o deresolve_class) class, |
81 Pretty.enclose "[" "]" [Pretty.block [(Pretty.str o deresolve_class) class, |
82 Pretty.enclose "[" "]" [(Pretty.str o lookup_tyvar tyvars) var]]]] |
82 Pretty.enclose "[" "]" [(Pretty.str o lookup_tyvar tyvars) var]]]] |
83 and applify_dictss tyvars p dss = |
83 and applify_dictss tyvars p dictss = |
84 applify "(" ")" (applify_dict tyvars) NOBR p (flat dss) |
84 applify "(" ")" (applify_dict tyvars) NOBR p (flat dictss) |
85 fun print_term tyvars is_pat some_thm vars fxy (IConst const) = |
85 fun print_term tyvars is_pat some_thm vars fxy (IConst const) = |
86 print_app tyvars is_pat some_thm vars fxy (const, []) |
86 print_app tyvars is_pat some_thm vars fxy (const, []) |
87 | print_term tyvars is_pat some_thm vars fxy (t as (t1 `$ t2)) = |
87 | print_term tyvars is_pat some_thm vars fxy (t as (t1 `$ t2)) = |
88 (case Code_Thingol.unfold_const_app t |
88 (case Code_Thingol.unfold_const_app t |
89 of SOME app => print_app tyvars is_pat some_thm vars fxy app |
89 of SOME app => print_app tyvars is_pat some_thm vars fxy app |
113 Pretty.enclose "(" ")" [constraint (print_var vars' some_v) (print_typ tyvars NOBR ty)], |
113 Pretty.enclose "(" ")" [constraint (print_var vars' some_v) (print_typ tyvars NOBR ty)], |
114 Pretty.str "=>" |
114 Pretty.str "=>" |
115 ], vars') |
115 ], vars') |
116 end |
116 end |
117 and print_app tyvars is_pat some_thm vars fxy |
117 and print_app tyvars is_pat some_thm vars fxy |
118 (app as (const as { sym, typargs, dom, dicts, ... }, ts)) = |
118 (app as (const as { sym, typargs, dom, dictss, ... }, ts)) = |
119 let |
119 let |
120 val typargs' = if is_pat then [] else typargs; |
120 val typargs' = if is_pat then [] else typargs; |
121 val syntax = case sym of |
121 val syntax = case sym of |
122 Constant const => const_syntax const |
122 Constant const => const_syntax const |
123 | _ => NONE; |
123 | _ => NONE; |
124 val applify_dicts = |
124 val applify_dicts = |
125 if is_pat orelse is_some syntax orelse is_constr sym |
125 if is_pat orelse is_some syntax orelse is_constr sym |
126 orelse Code_Thingol.unambiguous_dictss dicts |
126 orelse Code_Thingol.unambiguous_dictss dictss |
127 then fn p => K p |
127 then fn p => K p |
128 else applify_dictss tyvars; |
128 else applify_dictss tyvars; |
129 val (wanted, print') = case syntax of |
129 val (wanted, print') = case syntax of |
130 NONE => (args_num sym, fn fxy => fn ts => applify_dicts |
130 NONE => (args_num sym, fn fxy => fn ts => applify_dicts |
131 (gen_applify (is_constr sym) "(" ")" |
131 (gen_applify (is_constr sym) "(" ")" |
132 (print_term tyvars is_pat some_thm vars NOBR) fxy |
132 (print_term tyvars is_pat some_thm vars NOBR) fxy |
133 (applify "[" "]" (print_typ tyvars NOBR) |
133 (applify "[" "]" (print_typ tyvars NOBR) |
134 NOBR ((Pretty.str o deresolve) sym) typargs') ts) dicts) |
134 NOBR ((Pretty.str o deresolve) sym) typargs') ts) dictss) |
135 | SOME (k, Plain_printer s) => (k, fn fxy => fn ts => applify_dicts |
135 | SOME (k, Plain_printer s) => (k, fn fxy => fn ts => applify_dicts |
136 (applify "(" ")" |
136 (applify "(" ")" |
137 (print_term tyvars is_pat some_thm vars NOBR) fxy |
137 (print_term tyvars is_pat some_thm vars NOBR) fxy |
138 (applify "[" "]" (print_typ tyvars NOBR) |
138 (applify "[" "]" (print_typ tyvars NOBR) |
139 NOBR (Pretty.str s) typargs') ts) dicts) |
139 NOBR (Pretty.str s) typargs') ts) dictss) |
140 | SOME (k, Complex_printer print) => |
140 | SOME (k, Complex_printer print) => |
141 (k, fn fxy => fn ts => print (print_term tyvars is_pat some_thm) some_thm vars fxy |
141 (k, fn fxy => fn ts => print (print_term tyvars is_pat some_thm) some_thm vars fxy |
142 (ts ~~ take k dom)) |
142 (ts ~~ take k dom)) |
143 val ((vs_tys, (ts1, rty)), ts2) = |
143 val ((vs_tys, (ts1, rty)), ts2) = |
144 Code_Thingol.satisfied_application wanted app; |
144 Code_Thingol.satisfied_application wanted app; |