431 end; |
431 end; |
432 |
432 |
433 |
433 |
434 (* updaters *) |
434 (* updaters *) |
435 |
435 |
436 fun add_class_data ((class, superclasses), (cs, base_sort, insttab, phi, intro)) thy = |
436 fun add_class_data ((class, superclasses), (cs, base_sort, inst, phi, intro)) thy = |
437 let |
437 let |
438 val inst = map |
|
439 (SOME o the o Symtab.lookup insttab o fst o fst) |
|
440 (Locale.parameters_of_expr thy (Locale.Locale class)); |
|
441 val operations = map (fn (v_ty as (_, ty'), (c, ty)) => |
438 val operations = map (fn (v_ty as (_, ty'), (c, ty)) => |
442 (c, ((Free v_ty, (Logic.varifyT ty, 0)), (Free v_ty, ty')))) cs; |
439 (c, ((Free v_ty, (Logic.varifyT ty, 0)), (Free v_ty, ty')))) cs; |
443 val cs = (map o pairself) fst cs; |
440 val cs = (map o pairself) fst cs; |
444 val add_class = Graph.new_node (class, |
441 val add_class = Graph.new_node (class, |
445 mk_class_data ((cs, base_sort, inst, phi, intro), ([], operations))) |
442 mk_class_data ((cs, base_sort, map (SOME o Const) inst, phi, intro), ([], operations))) |
446 #> fold (curry Graph.add_edge class) superclasses; |
443 #> fold (curry Graph.add_edge class) superclasses; |
447 in |
444 in |
448 ClassData.map add_class thy |
445 ClassData.map add_class thy |
449 end; |
446 end; |
450 |
447 |
736 let |
733 let |
737 val class = Sign.full_name thy bname; |
734 val class = Sign.full_name thy bname; |
738 val (((sups, supconsts), (supsort, base_sort, mergeexpr)), elems_syn) = |
735 val (((sups, supconsts), (supsort, base_sort, mergeexpr)), elems_syn) = |
739 prep_spec thy raw_supclasses raw_includes_elems; |
736 prep_spec thy raw_supclasses raw_includes_elems; |
740 val other_consts = map (tap (Sign.the_const_type thy) o prep_param thy) raw_other_consts; |
737 val other_consts = map (tap (Sign.the_const_type thy) o prep_param thy) raw_other_consts; |
741 fun mk_inst class param_names cs = |
738 fun mk_inst class cs = |
742 Symtab.empty |
739 (map o apsnd o Term.map_type_tfree) (fn (v, _) => TFree (v, [class])) cs; |
743 |> fold2 (fn v => fn (c, ty) => Symtab.update (v, Const |
|
744 (c, Term.map_type_tfree (fn (v, _) => TFree (v, [class])) ty))) param_names cs; |
|
745 fun fork_syntax (Element.Fixes xs) = |
740 fun fork_syntax (Element.Fixes xs) = |
746 fold_map (fn (c, ty, syn) => cons (c, syn) #> pair (c, ty, NoSyn)) xs |
741 fold_map (fn (c, ty, syn) => cons (c, syn) #> pair (c, ty, NoSyn)) xs |
747 #>> Element.Fixes |
742 #>> Element.Fixes |
748 | fork_syntax x = pair x; |
743 | fork_syntax x = pair x; |
749 val (elems, global_syn) = fold_map fork_syntax elems_syn []; |
744 val (elems, global_syn) = fold_map fork_syntax elems_syn []; |
783 PureThy.note_thmss_qualified "" (NameSpace.append class classN) |
778 PureThy.note_thmss_qualified "" (NameSpace.append class classN) |
784 [((introN, []), [([class_intro], [])])] |
779 [((introN, []), [([class_intro], [])])] |
785 #-> (fn [(_, [class_intro])] => |
780 #-> (fn [(_, [class_intro])] => |
786 add_class_data ((class, sups), |
781 add_class_data ((class, sups), |
787 (map fst params ~~ consts, base_sort, |
782 (map fst params ~~ consts, base_sort, |
788 mk_inst class (map fst all_params) (map snd supconsts @ consts), |
783 mk_inst class (map snd supconsts @ consts), |
789 calculate_morphism class (supconsts @ (map (fst o fst) params ~~ consts)), class_intro)) |
784 calculate_morphism class (supconsts @ (map (fst o fst) params ~~ consts)), class_intro)) |
790 #> class_interpretation class axioms [] |
785 #> class_interpretation class axioms [] |
791 ))))) |
786 ))))) |
792 |> pair class |
787 |> pair class |
793 end; |
788 end; |