src/Pure/axclass.ML
changeset 24929 408becab067e
parent 24920 2a45e400fdad
child 24964 526df61afe97
equal deleted inserted replaced
24928:3419943838f5 24929:408becab067e
    16     (class * ((string * typ) list * thm list)) * theory
    16     (class * ((string * typ) list * thm list)) * theory
    17   val add_classrel: thm -> theory -> theory
    17   val add_classrel: thm -> theory -> theory
    18   val add_arity: thm -> theory -> theory
    18   val add_arity: thm -> theory -> theory
    19   val prove_classrel: class * class -> tactic -> theory -> theory
    19   val prove_classrel: class * class -> tactic -> theory -> theory
    20   val prove_arity: string * sort list * sort -> tactic -> theory -> theory
    20   val prove_arity: string * sort list * sort -> tactic -> theory -> theory
    21   val get_definition: theory -> class -> {def: thm, intro: thm, axioms: thm list,
    21   val get_info: theory -> class -> {def: thm, intro: thm, axioms: thm list,
    22     params: (string * typ) list}
    22     params: (string * typ) list}
    23   val class_intros: theory -> thm list
    23   val class_intros: theory -> thm list
    24   val class_of_param: theory -> string -> class option
    24   val class_of_param: theory -> string -> class option
    25   val params_of_class: theory -> class -> string * (string * typ) list
    25   val params_of_class: theory -> class -> string * (string * typ) list
    26   val print_axclasses: theory -> unit
    26   val print_axclasses: theory -> unit
    27   val cert_classrel: theory -> class * class -> class * class
    27   val cert_classrel: theory -> class * class -> class * class
    28   val read_classrel: theory -> xstring * xstring -> class * class
    28   val read_classrel: theory -> xstring * xstring -> class * class
    29   val axiomatize_class: bstring * xstring list -> theory -> theory
    29   val axiomatize_class: bstring * class list -> theory -> theory
    30   val axiomatize_class_i: bstring * class list -> theory -> theory
    30   val axiomatize_class_cmd: bstring * xstring list -> theory -> theory
    31   val axiomatize_classrel: (xstring * xstring) list -> theory -> theory
    31   val axiomatize_classrel: (class * class) list -> theory -> theory
    32   val axiomatize_classrel_i: (class * class) list -> theory -> theory
    32   val axiomatize_classrel_cmd: (xstring * xstring) list -> theory -> theory
    33   val axiomatize_arity: xstring * string list * string -> theory -> theory
    33   val axiomatize_arity: arity -> theory -> theory
    34   val axiomatize_arity_i: arity -> theory -> theory
    34   val axiomatize_arity_cmd: xstring * string list * string -> theory -> theory
    35   type cache
    35   type cache
       
    36   val of_sort: theory -> typ * sort -> cache -> thm list * cache  (*exception Sorts.CLASS_ERROR*)
    36   val cache: cache
    37   val cache: cache
    37   val of_sort: theory -> typ * sort -> cache -> thm list * cache  (*exception Sorts.CLASS_ERROR*)
       
    38 end;
    38 end;
    39 
    39 
    40 structure AxClass: AX_CLASS =
    40 structure AxClass: AX_CLASS =
    41 struct
    41 struct
    42 
    42 
   111 val get_axclasses = #1 o AxClassData.get;
   111 val get_axclasses = #1 o AxClassData.get;
   112 fun map_axclasses f = AxClassData.map (apfst f);
   112 fun map_axclasses f = AxClassData.map (apfst f);
   113 
   113 
   114 val lookup_def = Symtab.lookup o #1 o get_axclasses;
   114 val lookup_def = Symtab.lookup o #1 o get_axclasses;
   115 
   115 
   116 fun get_definition thy c =
   116 fun get_info thy c =
   117   (case lookup_def thy c of
   117   (case lookup_def thy c of
   118     SOME (AxClass info) => info
   118     SOME (AxClass info) => info
   119   | NONE => error ("No such axclass: " ^ quote c));
   119   | NONE => error ("No such axclass: " ^ quote c));
   120 
   120 
   121 fun class_intros thy =
   121 fun class_intros thy =
   134 fun all_params_of thy S = get_params thy (fn c => Sign.subsort thy (S, [c]));
   134 fun all_params_of thy S = get_params thy (fn c => Sign.subsort thy (S, [c]));
   135 
   135 
   136 fun class_of_param thy =
   136 fun class_of_param thy =
   137   AList.lookup (op =) (#2 (get_axclasses thy));
   137   AList.lookup (op =) (#2 (get_axclasses thy));
   138 
   138 
   139 fun params_of_class thy class = (Name.aT, #params (get_definition thy class));
   139 fun params_of_class thy class = (Name.aT, #params (get_info thy class));
   140 
   140 
   141 
   141 
   142 (* maintain instances *)
   142 (* maintain instances *)
   143 
   143 
   144 val get_instances = #2 o AxClassData.get;
   144 val get_instances = #2 o AxClassData.get;
   154 fun put_classrel arg = map_instances (fn (classrel, arities) =>
   154 fun put_classrel arg = map_instances (fn (classrel, arities) =>
   155   (insert (eq_fst op =) arg classrel, arities));
   155   (insert (eq_fst op =) arg classrel, arities));
   156 
   156 
   157 
   157 
   158 fun the_arity thy a (c, Ss) =
   158 fun the_arity thy a (c, Ss) =
   159   (case AList.lookup (op =) (Symtab.lookup_list (#2 (get_instances thy)) a) (c, Ss)  of
   159   (case AList.lookup (op =) (Symtab.lookup_list (#2 (get_instances thy)) a) (c, Ss) of
   160     SOME th => Thm.transfer thy th
   160     SOME th => Thm.transfer thy th
   161   | NONE => error ("Unproven type arity " ^
   161   | NONE => error ("Unproven type arity " ^
   162       Syntax.string_of_arity (ProofContext.init thy) (a, Ss, [c])));
   162       Syntax.string_of_arity (ProofContext.init thy) (a, Ss, [c])));
   163 
   163 
   164 fun put_arity ((t, Ss, c), th) = map_instances (fn (classrel, arities) =>
   164 fun put_arity ((t, Ss, c), th) = map_instances (fn (classrel, arities) =>
   387     |> fold_map add_const consts
   387     |> fold_map add_const consts
   388     ||> Sign.restore_naming thy
   388     ||> Sign.restore_naming thy
   389     |-> (fn cs => mk_axioms cs
   389     |-> (fn cs => mk_axioms cs
   390     #-> (fn axioms_prop => define_class (name, superclasses)
   390     #-> (fn axioms_prop => define_class (name, superclasses)
   391            (map fst cs @ other_consts) axioms_prop
   391            (map fst cs @ other_consts) axioms_prop
   392     #-> (fn class => `(fn thy => get_definition thy class)
   392     #-> (fn class => `(fn thy => get_info thy class)
   393     #-> (fn {axioms, ...} => fold (add_constraint class) cs
   393     #-> (fn {axioms, ...} => fold (add_constraint class) cs
   394     #> pair (class, (cs, axioms))))))
   394     #> pair (class, (cs, axioms))))))
   395   end;
   395   end;
   396 
   396 
   397 
   397 
   429     |> Theory.add_deps "" (class_const class) (map class_const super)
   429     |> Theory.add_deps "" (class_const class) (map class_const super)
   430   end;
   430   end;
   431 
   431 
   432 in
   432 in
   433 
   433 
   434 val axiomatize_class = ax_class Sign.read_class read_classrel;
   434 val axiomatize_class = ax_class Sign.certify_class cert_classrel;
   435 val axiomatize_class_i = ax_class Sign.certify_class cert_classrel;
   435 val axiomatize_class_cmd = ax_class Sign.read_class read_classrel;
   436 val axiomatize_classrel = ax_classrel read_classrel;
   436 val axiomatize_classrel = ax_classrel cert_classrel;
   437 val axiomatize_classrel_i = ax_classrel cert_classrel;
   437 val axiomatize_classrel_cmd = ax_classrel read_classrel;
   438 val axiomatize_arity = ax_arity Sign.read_arity;
   438 val axiomatize_arity = ax_arity Sign.cert_arity;
   439 val axiomatize_arity_i = ax_arity Sign.cert_arity;
   439 val axiomatize_arity_cmd = ax_arity Sign.read_arity;
   440 
   440 
   441 end;
   441 end;
   442 
   442 
   443 
   443 
   444 
   444 
   445 (** explicit derivations -- cached **)
   445 (** explicit derivations -- cached **)
   446 
   446 
   447 datatype cache = Types of (class * thm) list Typtab.table;
   447 datatype cache = Types of (class * thm) list Typtab.table;
   448 val cache = Types Typtab.empty;
       
   449 
   448 
   450 local
   449 local
   451 
   450 
   452 fun lookup_type (Types cache) = AList.lookup (op =) o Typtab.lookup_list cache;
   451 fun lookup_type (Types cache) = AList.lookup (op =) o Typtab.lookup_list cache;
   453 fun insert_type T der (Types cache) = Types (Typtab.insert_list (eq_fst op =) (T, der) cache);
   452 fun insert_type T der (Types cache) = Types (Typtab.insert_list (eq_fst op =) (T, der) cache);
   488         |> Thm.adjust_maxidx_thm ~1);
   487         |> Thm.adjust_maxidx_thm ~1);
   489   in (ths, cache') end;
   488   in (ths, cache') end;
   490 
   489 
   491 end;
   490 end;
   492 
   491 
       
   492 val cache = Types Typtab.empty;
       
   493 
   493 end;
   494 end;