src/Pure/Tools/class_package.ML
changeset 22930 f99617e7103f
parent 22846 fb79144af9a3
child 22997 d4f3b015b50b
equal deleted inserted replaced
22929:e6b6f8dd03e9 22930:f99617e7103f
    31 
    31 
    32   (* experimental class target *)
    32   (* experimental class target *)
    33   val class_of_locale: theory -> string -> class option
    33   val class_of_locale: theory -> string -> class option
    34   val add_def_in_class: local_theory -> string
    34   val add_def_in_class: local_theory -> string
    35     -> (string * Syntax.mixfix) * ((string * Attrib.src list) * (term * thm)) -> theory -> theory
    35     -> (string * Syntax.mixfix) * ((string * Attrib.src list) * (term * thm)) -> theory -> theory
       
    36   val CLASS_TARGET: bool ref
    36 
    37 
    37   val print_classes: theory -> unit
    38   val print_classes: theory -> unit
    38   val intro_classes_tac: thm list -> tactic
    39   val intro_classes_tac: thm list -> tactic
    39   val default_intro_classes_tac: thm list -> tactic
    40   val default_intro_classes_tac: thm list -> tactic
    40 end;
    41 end;
    95 fun axclass_params (name, raw_superclasses) raw_consts raw_dep_axioms other_consts thy =
    96 fun axclass_params (name, raw_superclasses) raw_consts raw_dep_axioms other_consts thy =
    96   let
    97   let
    97     val superclasses = map (Sign.certify_class thy) raw_superclasses;
    98     val superclasses = map (Sign.certify_class thy) raw_superclasses;
    98     val consts = (map o apfst o apsnd) (Sign.certify_typ thy) raw_consts;
    99     val consts = (map o apfst o apsnd) (Sign.certify_typ thy) raw_consts;
    99     fun add_const ((c, ty), syn) =
   100     fun add_const ((c, ty), syn) =
   100       Sign.add_consts_authentic [(c, ty, syn)] #> pair (Sign.full_name thy c, ty);
   101       Sign.add_consts_authentic [(c, ty, syn)]
       
   102       #> pair (Sign.full_name thy c, ty);
   101     fun mk_axioms cs thy =
   103     fun mk_axioms cs thy =
   102       raw_dep_axioms thy cs
   104       raw_dep_axioms thy cs
   103       |> (map o apsnd o map) (Sign.cert_prop thy)
   105       |> (map o apsnd o map) (Sign.cert_prop thy)
   104       |> rpair thy;
   106       |> rpair thy;
   105     fun add_constraint class (c, ty) =
   107     fun add_constraint class (c, ty) =
   106       Sign.add_const_constraint_i (c, SOME (Term.map_type_tfree (fn (v, _) => TFree (v, [class])) ty));
   108       Sign.add_const_constraint_i (c, SOME (Term.map_type_tfree (fn (v, _) => TFree (v, [class])) ty));
   107   in
   109   in
   108     thy
   110     thy
       
   111     (* |> Theory.add_path name *)
   109     |> fold_map add_const consts
   112     |> fold_map add_const consts
       
   113     (* ||> Theory.restore_naming thy *)
   110     |-> (fn cs => mk_axioms cs
   114     |-> (fn cs => mk_axioms cs
   111     #-> (fn axioms_prop => AxClass.define_class (name, superclasses) (map fst cs @ other_consts) axioms_prop
   115     #-> (fn axioms_prop => AxClass.define_class (name, superclasses) (map fst cs @ other_consts) axioms_prop
   112     #-> (fn class => `(fn thy => AxClass.get_definition thy class)
   116     #-> (fn class => `(fn thy => AxClass.get_definition thy class)
   113     #-> (fn {intro, axioms, ...} => fold (add_constraint class) cs
   117     #-> (fn {intro, axioms, ...} => fold (add_constraint class) cs
   114     #> pair (class, ((intro, (map Thm.prop_of axioms, axioms)), cs))))))
   118     #> pair (class, ((intro, (map Thm.prop_of axioms, axioms)), cs))))))
   623         val tfrees = map string_of_tfree (Term.add_tfrees t []);
   627         val tfrees = map string_of_tfree (Term.add_tfrees t []);
   624         val tvars = map string_of_tvar (Term.add_tvars t []);
   628         val tvars = map string_of_tvar (Term.add_tvars t []);
   625       in term :: tfrees @ tvars end;
   629       in term :: tfrees @ tvars end;
   626   in (map warning (print_term t); map warning (print_term prop)) end;
   630   in (map warning (print_term t); map warning (print_term prop)) end;
   627 
   631 
       
   632 val CLASS_TARGET = ref true;
       
   633 
   628 fun add_def_in_class lthy class ((c, syn), ((name, atts), (rhs, eq))) thy =
   634 fun add_def_in_class lthy class ((c, syn), ((name, atts), (rhs, eq))) thy =
   629   let
   635   let
   630     val prfx = (Logic.const_of_class o NameSpace.base) class;
   636     val prfx = (Logic.const_of_class o NameSpace.base) class;
   631     val rhs' = global_term thy [class] rhs;
   637     val rhs' = global_term thy [class] rhs;
   632     val (syn', _) = fork_mixfix true NONE syn;
   638     val (syn', _) = fork_mixfix true NONE syn;