216 ) (map print_classparam classparams) |
216 ) (map print_classparam classparams) |
217 end |
217 end |
218 | print_stmt (_, Code_Thingol.Classinst ((class, (tyco, vs)), (_, (classparam_instances, _)))) = |
218 | print_stmt (_, Code_Thingol.Classinst ((class, (tyco, vs)), (_, (classparam_instances, _)))) = |
219 let |
219 let |
220 val tyvars = intro_vars (map fst vs) reserved; |
220 val tyvars = intro_vars (map fst vs) reserved; |
221 fun print_classparam_instance ((classparam, const), (thm, _)) = case syntax_const classparam |
221 fun requires_args classparam = case syntax_const classparam |
222 of NONE => semicolon [ |
222 of NONE => 0 |
223 (str o deresolve_base) classparam, |
223 | SOME (Code_Printer.Plain_const_syntax _) => 0 |
224 str "=", |
224 | SOME (Code_Printer.Complex_const_syntax (k,_ )) => k; |
225 print_app tyvars (SOME thm) reserved NOBR (const, []) |
225 fun print_classparam_instance ((classparam, const), (thm, _)) = |
226 ] |
226 case requires_args classparam |
227 | SOME (k, pr) => |
227 of 0 => semicolon [ |
228 let |
228 (str o deresolve_base) classparam, |
229 val (c, (_, tys)) = const; |
|
230 val (vs, rhs) = (apfst o map) fst |
|
231 (Code_Thingol.unfold_abs (Code_Thingol.eta_expand k (const, []))); |
|
232 val s = if (is_some o syntax_const) c |
|
233 then NONE else (SOME o Long_Name.base_name o deresolve) c; |
|
234 val vars = reserved |
|
235 |> intro_vars (map_filter I (s :: vs)); |
|
236 val lhs = IConst (classparam, (([], []), tys)) `$$ map IVar vs; |
|
237 (*dictionaries are not relevant at this late stage*) |
|
238 in |
|
239 semicolon [ |
|
240 print_term tyvars (SOME thm) vars NOBR lhs, |
|
241 str "=", |
229 str "=", |
242 print_term tyvars (SOME thm) vars NOBR rhs |
230 print_app tyvars (SOME thm) reserved NOBR (const, []) |
243 ] |
231 ] |
244 end; |
232 | k => |
|
233 let |
|
234 val (c, (_, tys)) = const; |
|
235 val (vs, rhs) = (apfst o map) fst |
|
236 (Code_Thingol.unfold_abs (Code_Thingol.eta_expand k (const, []))); |
|
237 val s = if (is_some o syntax_const) c |
|
238 then NONE else (SOME o Long_Name.base_name o deresolve) c; |
|
239 val vars = reserved |
|
240 |> intro_vars (map_filter I (s :: vs)); |
|
241 val lhs = IConst (classparam, (([], []), tys)) `$$ map IVar vs; |
|
242 (*dictionaries are not relevant at this late stage*) |
|
243 in |
|
244 semicolon [ |
|
245 print_term tyvars (SOME thm) vars NOBR lhs, |
|
246 str "=", |
|
247 print_term tyvars (SOME thm) vars NOBR rhs |
|
248 ] |
|
249 end; |
245 in |
250 in |
246 Pretty.block_enclose ( |
251 Pretty.block_enclose ( |
247 Pretty.block [ |
252 Pretty.block [ |
248 str "instance ", |
253 str "instance ", |
249 Pretty.block (print_typcontext tyvars vs), |
254 Pretty.block (print_typcontext tyvars vs), |