222 |
222 |
223 (* class relations *) |
223 (* class relations *) |
224 |
224 |
225 fun cert_classrel thy raw_rel = |
225 fun cert_classrel thy raw_rel = |
226 let |
226 let |
|
227 val string_of_sort = Syntax.string_of_sort_global thy; |
227 val (c1, c2) = pairself (Sign.certify_class thy) raw_rel; |
228 val (c1, c2) = pairself (Sign.certify_class thy) raw_rel; |
228 val _ = Sign.primitive_classrel (c1, c2) (Theory.copy thy); |
229 val _ = Sign.primitive_classrel (c1, c2) (Theory.copy thy); |
229 val _ = |
230 val _ = |
230 (case subtract (op =) (all_params_of thy [c1]) (all_params_of thy [c2]) of |
231 (case subtract (op =) (all_params_of thy [c1]) (all_params_of thy [c2]) of |
231 [] => () |
232 [] => () |
232 | xs => raise TYPE ("Class " ^ Sign.string_of_sort thy [c1] ^ " lacks parameter(s) " ^ |
233 | xs => raise TYPE ("Class " ^ string_of_sort [c1] ^ " lacks parameter(s) " ^ |
233 commas_quote xs ^ " of " ^ Sign.string_of_sort thy [c2], [], [])); |
234 commas_quote xs ^ " of " ^ string_of_sort [c2], [], [])); |
234 in (c1, c2) end; |
235 in (c1, c2) end; |
235 |
236 |
236 fun read_classrel thy raw_rel = |
237 fun read_classrel thy raw_rel = |
237 cert_classrel thy (pairself (Sign.read_class thy) raw_rel) |
238 cert_classrel thy (pairself (Sign.read_class thy) raw_rel) |
238 handle TYPE (msg, _, _) => error msg; |
239 handle TYPE (msg, _, _) => error msg; |
312 of SOME class => class |
313 of SOME class => class |
313 | NONE => error ("Not a class parameter: " ^ quote c); |
314 | NONE => error ("Not a class parameter: " ^ quote c); |
314 val tyco = case inst_tyco_of thy (c, T) |
315 val tyco = case inst_tyco_of thy (c, T) |
315 of SOME tyco => tyco |
316 of SOME tyco => tyco |
316 | NONE => error ("Illegal type for instantiation of class parameter: " |
317 | NONE => error ("Illegal type for instantiation of class parameter: " |
317 ^ quote (c ^ " :: " ^ Sign.string_of_typ thy T)); |
318 ^ quote (c ^ " :: " ^ Syntax.string_of_typ_global thy T)); |
318 val name_inst = instance_name (tyco, class) ^ "_inst"; |
319 val name_inst = instance_name (tyco, class) ^ "_inst"; |
319 val c' = NameSpace.base c ^ "_" ^ NameSpace.base tyco; |
320 val c' = NameSpace.base c ^ "_" ^ NameSpace.base tyco; |
320 val T' = Type.strip_sorts T; |
321 val T' = Type.strip_sorts T; |
321 in |
322 in |
322 thy |
323 thy |
516 (fn T as TFree (_, S) => insert (eq_fst op =) (T, S) |
517 (fn T as TFree (_, S) => insert (eq_fst op =) (T, S) |
517 | T as TVar (_, S) => insert (eq_fst op =) (T, S) |
518 | T as TVar (_, S) => insert (eq_fst op =) (T, S) |
518 | _ => I) typ []; |
519 | _ => I) typ []; |
519 val hyps = vars |
520 val hyps = vars |
520 |> map (fn (T, S) => (T, Drule.sort_triv thy (T, S) ~~ S)); |
521 |> map (fn (T, S) => (T, Drule.sort_triv thy (T, S) ~~ S)); |
521 val ths = (typ, sort) |> Sorts.of_sort_derivation (Sign.pp thy) (Sign.classes_of thy) |
522 val ths = (typ, sort) |
|
523 |> Sorts.of_sort_derivation (Syntax.pp_global thy) (Sign.classes_of thy) |
522 {class_relation = |
524 {class_relation = |
523 fn (th, c1) => fn c2 => th RS the_classrel thy (c1, c2), |
525 fn (th, c1) => fn c2 => th RS the_classrel thy (c1, c2), |
524 type_constructor = |
526 type_constructor = |
525 fn a => fn dom => fn c => |
527 fn a => fn dom => fn c => |
526 let val Ss = map (map snd) dom and ths = maps (map fst) dom |
528 let val Ss = map (map snd) dom and ths = maps (map fst) dom |
534 fun of_sort thy (typ, sort) cache = |
536 fun of_sort thy (typ, sort) cache = |
535 let |
537 let |
536 val sort' = filter (is_none o lookup_type cache typ) sort; |
538 val sort' = filter (is_none o lookup_type cache typ) sort; |
537 val ths' = derive_type thy (typ, sort') |
539 val ths' = derive_type thy (typ, sort') |
538 handle ERROR msg => cat_error msg ("The error(s) above occurred for sort derivation: " ^ |
540 handle ERROR msg => cat_error msg ("The error(s) above occurred for sort derivation: " ^ |
539 Sign.string_of_typ thy typ ^ " :: " ^ Sign.string_of_sort thy sort'); |
541 Syntax.string_of_typ_global thy typ ^ " :: " ^ Syntax.string_of_sort_global thy sort'); |
540 val cache' = cache |> fold (insert_type typ) (sort' ~~ ths'); |
542 val cache' = cache |> fold (insert_type typ) (sort' ~~ ths'); |
541 val ths = |
543 val ths = |
542 sort |> map (fn c => |
544 sort |> map (fn c => |
543 Goal.finish (the (lookup_type cache' typ c) RS |
545 Goal.finish (the (lookup_type cache' typ c) RS |
544 Goal.init (Thm.cterm_of thy (Logic.mk_inclass (typ, c)))) |
546 Goal.init (Thm.cterm_of thy (Logic.mk_inclass (typ, c)))) |