212 |> Symtab.insert_list (eq_fst op =) arity' |
212 |> Symtab.insert_list (eq_fst op =) arity' |
213 |> insert_arity_completions thy arity' |
213 |> insert_arity_completions thy arity' |
214 |> snd)) |
214 |> snd)) |
215 end; |
215 end; |
216 |
216 |
217 fun complete_arities thy = |
217 fun complete_arities thy = |
218 let |
218 let |
219 val arities = snd (get_instances thy); |
219 val arities = snd (get_instances thy); |
220 val (completions, arities') = arities |
220 val (completions, arities') = arities |
221 |> fold_map (insert_arity_completions thy) (Symtab.dest_list arities) |
221 |> fold_map (insert_arity_completions thy) (Symtab.dest_list arities) |
222 |>> flat; |
222 |>> flat; |
573 fun insert_type T der (Types cache) = Types (Typtab.insert_list (eq_fst op =) (T, der) cache); |
573 fun insert_type T der (Types cache) = Types (Typtab.insert_list (eq_fst op =) (T, der) cache); |
574 |
574 |
575 fun derive_type _ (_, []) = [] |
575 fun derive_type _ (_, []) = [] |
576 | derive_type thy (typ, sort) = |
576 | derive_type thy (typ, sort) = |
577 let |
577 let |
|
578 val certT = Thm.ctyp_of thy; |
578 val vars = Term.fold_atyps |
579 val vars = Term.fold_atyps |
579 (fn T as TFree (_, S) => insert (eq_fst op =) (T, S) |
580 (fn T as TFree (_, S) => insert (eq_fst op =) (T, S) |
580 | T as TVar (_, S) => insert (eq_fst op =) (T, S) |
581 | T as TVar (_, S) => insert (eq_fst op =) (T, S) |
581 | _ => I) typ []; |
582 | _ => I) typ []; |
582 val hyps = vars |
583 val hyps = vars |
583 |> map (fn (T, S) => (T, Thm.sort_triv thy (T, S) ~~ S)); |
584 |> map (fn (T, S) => (T, Thm.of_sort (certT T, S) ~~ S)); |
584 val ths = (typ, sort) |
585 val ths = (typ, sort) |
585 |> Sorts.of_sort_derivation (Syntax.pp_global thy) (Sign.classes_of thy) |
586 |> Sorts.of_sort_derivation (Syntax.pp_global thy) (Sign.classes_of thy) |
586 {class_relation = |
587 {class_relation = |
587 fn (th, c1) => fn c2 => th RS the_classrel thy (c1, c2), |
588 fn (th, c1) => fn c2 => th RS the_classrel thy (c1, c2), |
588 type_constructor = |
589 type_constructor = |