src/Pure/Isar/class.ML
author haftmann
Mon, 10 Dec 2007 11:24:15 +0100
changeset 25597 34860182b250
parent 25574 016f677ad7b8
child 25603 4b7a58fc168c
permissions -rw-r--r--
moved instance parameter management from class.ML to axclass.ML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Isar/class.ML
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     2
    ID:         $Id$
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     4
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     5
Type classes derived from primitive axclasses and locales.
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     6
*)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     7
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     8
signature CLASS =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
     9
sig
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    10
  (*classes*)
25002
haftmann
parents: 24981
diff changeset
    11
  val class: bstring -> class list -> Element.context_i Locale.element list
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    12
    -> string list -> theory -> string * Proof.context
25002
haftmann
parents: 24981
diff changeset
    13
  val class_cmd: bstring -> xstring list -> Element.context Locale.element list
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    14
    -> xstring list -> theory -> string * Proof.context
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    15
25311
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
    16
  val init: class -> theory -> Proof.context
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    17
  val logical_const: string -> Markup.property list
25104
26b9a7db3386 tuned interfaces;
wenzelm
parents: 25103
diff changeset
    18
    -> (string * mixfix) * term -> theory -> theory
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    19
  val syntactic_const: string -> Syntax.mode -> Markup.property list
25104
26b9a7db3386 tuned interfaces;
wenzelm
parents: 25103
diff changeset
    20
    -> (string * mixfix) * term -> theory -> theory
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
    21
  val refresh_syntax: class -> Proof.context -> Proof.context
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    22
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    23
  val intro_classes_tac: thm list -> tactic
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    24
  val default_intro_classes_tac: thm list -> tactic
25195
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    25
  val prove_subclass: class * class -> thm list -> Proof.context
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    26
    -> theory -> theory
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    27
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    28
  val class_prefix: string -> string
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    29
  val is_class: theory -> class -> bool
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    30
  val these_params: theory -> sort -> (string * (string * typ)) list
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    31
  val print_classes: theory -> unit
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24304
diff changeset
    32
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    33
  (*instances*)
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
    34
  val init_instantiation: string list * sort list * sort -> theory -> local_theory
01753a944433 improved
haftmann
parents: 25518
diff changeset
    35
  val prep_spec: local_theory -> term -> term
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    36
  val instantiation_instance: (local_theory -> local_theory) -> local_theory -> Proof.state
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    37
  val prove_instantiation_instance: (Proof.context -> tactic) -> local_theory -> local_theory
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    38
  val conclude_instantiation: local_theory -> local_theory
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    39
  val instantiation_param: Proof.context -> string -> string option
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    40
  val confirm_declaration: string -> local_theory -> local_theory
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    41
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    42
  (*old axclass layer*)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    43
  val axclass_cmd: bstring * xstring list
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    44
    -> ((bstring * Attrib.src list) * string list) list
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    45
    -> theory -> class * theory
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    46
  val classrel_cmd: xstring * xstring -> theory -> Proof.state
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    47
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
    48
  (*old instance layer*)
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
    49
  val instance_arity: (theory -> theory) -> arity -> theory -> Proof.state
01753a944433 improved
haftmann
parents: 25518
diff changeset
    50
  val instance_arity_cmd: bstring * xstring list * xstring -> theory -> Proof.state
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    51
end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    52
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    53
structure Class : CLASS =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    54
struct
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    55
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    56
(** auxiliary **)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
    57
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
    58
val classN = "class";
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
    59
val introN = "intro";
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
    60
25002
haftmann
parents: 24981
diff changeset
    61
fun prove_interpretation tac prfx_atts expr inst =
haftmann
parents: 24981
diff changeset
    62
  Locale.interpretation_i I prfx_atts expr inst
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    63
  #> Proof.global_terminal_proof
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    64
      (Method.Basic (K (Method.SIMPLE_METHOD tac), Position.none), NONE)
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    65
  #> ProofContext.theory_of;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    66
25195
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    67
fun prove_interpretation_in tac after_qed (name, expr) =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    68
  Locale.interpretation_in_locale
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    69
      (ProofContext.theory after_qed) (name, expr)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    70
  #> Proof.global_terminal_proof
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    71
      (Method.Basic (K (Method.SIMPLE_METHOD tac), Position.none), NONE)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    72
  #> ProofContext.theory_of;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
    73
25020
f1344290e420 (un)overload: full rewrite;
wenzelm
parents: 25010
diff changeset
    74
fun OF_LAST thm1 thm2 = thm1 RSN (Thm.nprems_of thm2, thm2);
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    75
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    76
fun strip_all_ofclass thy sort =
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    77
  let
24847
bc15dcaed517 replaced AxClass.param_tyvarname by Name.aT;
wenzelm
parents: 24836
diff changeset
    78
    val typ = TVar ((Name.aT, 0), sort);
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    79
    fun prem_inclass t =
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    80
      case Logic.strip_imp_prems t
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    81
       of ofcls :: _ => try Logic.dest_inclass ofcls
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    82
        | [] => NONE;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    83
    fun strip_ofclass class thm =
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    84
      thm OF (fst o AxClass.of_sort thy (typ, [class])) AxClass.cache;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    85
    fun strip thm = case (prem_inclass o Thm.prop_of) thm
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    86
     of SOME (_, class) => thm |> strip_ofclass class |> strip
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    87
      | NONE => thm;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    88
  in strip end;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    89
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    90
fun get_remove_global_constraint c thy =
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    91
  let
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    92
    val ty = Sign.the_const_constraint thy c;
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    93
  in
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    94
    thy
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    95
    |> Sign.add_const_constraint (c, NONE)
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    96
    |> pair (c, Logic.unvarifyT ty)
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    97
  end;
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
    98
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
    99
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   100
(** primitive axclass and instance commands **)
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   101
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   102
fun axclass_cmd (class, raw_superclasses) raw_specs thy =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   103
  let
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   104
    val ctxt = ProofContext.init thy;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   105
    val superclasses = map (Sign.read_class thy) raw_superclasses;
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   106
    val name_atts = map ((apsnd o map) (Attrib.attribute thy) o fst)
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   107
      raw_specs;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   108
    val axiomss = ProofContext.read_propp (ctxt, map (map (rpair []) o snd)
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   109
          raw_specs)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   110
      |> snd
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   111
      |> (map o map) fst;
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   112
  in
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   113
    AxClass.define_class (class, superclasses) []
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   114
      (name_atts ~~ axiomss) thy
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   115
  end;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   116
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   117
local
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   118
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   119
fun gen_instance mk_prop add_thm after_qed insts thy =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   120
  let
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   121
    fun after_qed' results =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   122
      ProofContext.theory ((fold o fold) add_thm results #> after_qed);
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   123
  in
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   124
    thy
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   125
    |> ProofContext.init
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   126
    |> Proof.theorem_i NONE after_qed' ((map (fn t => [(t, [])])
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   127
        o mk_prop thy) insts)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   128
  end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   129
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   130
in
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   131
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   132
val instance_arity =
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   133
  gen_instance (Logic.mk_arities oo Sign.cert_arity) AxClass.add_arity;
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25485
diff changeset
   134
val instance_arity_cmd =
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25485
diff changeset
   135
  gen_instance (Logic.mk_arities oo Sign.read_arity) AxClass.add_arity I;
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   136
val classrel =
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   137
  gen_instance (single oo (Logic.mk_classrel oo AxClass.cert_classrel)) AxClass.add_classrel I;
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   138
val classrel_cmd =
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   139
  gen_instance (single oo (Logic.mk_classrel oo AxClass.read_classrel)) AxClass.add_classrel I;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   140
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   141
end; (*local*)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   142
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   143
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   144
(** class data **)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   145
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   146
datatype class_data = ClassData of {
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   147
  consts: (string * string) list
24836
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   148
    (*locale parameter ~> constant name*),
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   149
  base_sort: sort,
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   150
  inst: term option list
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   151
    (*canonical interpretation*),
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   152
  morphism: morphism,
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   153
    (*partial morphism of canonical interpretation*)
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   154
  intro: thm,
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   155
  defs: thm list,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   156
  operations: (string * (class * (typ * term))) list
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   157
};
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   158
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   159
fun rep_class_data (ClassData d) = d;
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   160
fun mk_class_data ((consts, base_sort, inst, morphism, intro),
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   161
    (defs, operations)) =
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   162
  ClassData { consts = consts, base_sort = base_sort, inst = inst,
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   163
    morphism = morphism, intro = intro, defs = defs,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   164
    operations = operations };
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   165
fun map_class_data f (ClassData { consts, base_sort, inst, morphism, intro,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   166
    defs, operations }) =
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   167
  mk_class_data (f ((consts, base_sort, inst, morphism, intro),
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   168
    (defs, operations)));
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   169
fun merge_class_data _ (ClassData { consts = consts,
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   170
    base_sort = base_sort, inst = inst, morphism = morphism, intro = intro,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   171
    defs = defs1, operations = operations1 },
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   172
  ClassData { consts = _, base_sort = _, inst = _, morphism = _, intro = _,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   173
    defs = defs2, operations = operations2 }) =
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   174
  mk_class_data ((consts, base_sort, inst, morphism, intro),
24914
95cda5dd58d5 added proper subclass concept; improved class target
haftmann
parents: 24901
diff changeset
   175
    (Thm.merge_thms (defs1, defs2),
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   176
      AList.merge (op =) (K true) (operations1, operations2)));
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   177
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   178
structure ClassData = TheoryDataFun
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   179
(
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   180
  type T = class_data Graph.T
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   181
  val empty = Graph.empty;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   182
  val copy = I;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   183
  val extend = I;
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   184
  fun merge _ = Graph.join merge_class_data;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   185
);
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   186
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   187
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   188
(* queries *)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   189
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   190
val lookup_class_data = Option.map rep_class_data oo try o Graph.get_node o ClassData.get;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   191
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   192
fun the_class_data thy class = case lookup_class_data thy class
25020
f1344290e420 (un)overload: full rewrite;
wenzelm
parents: 25010
diff changeset
   193
 of NONE => error ("Undeclared class " ^ quote class)
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   194
  | SOME data => data;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   195
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   196
val is_class = is_some oo lookup_class_data;
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   197
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   198
val ancestry = Graph.all_succs o ClassData.get;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   199
25002
haftmann
parents: 24981
diff changeset
   200
fun these_params thy =
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   201
  let
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   202
    fun params class =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   203
      let
24930
cc2e0e8c81af renamed AxClass.get_definition to AxClass.get_info (again);
wenzelm
parents: 24920
diff changeset
   204
        val const_typs = (#params o AxClass.get_info thy) class;
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   205
        val const_names = (#consts o the_class_data thy) class;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   206
      in
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   207
        (map o apsnd) (fn c => (c, (the o AList.lookup (op =) const_typs) c)) const_names
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   208
      end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   209
  in maps params o ancestry thy end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   210
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   211
fun these_defs thy = maps (these o Option.map #defs o lookup_class_data thy) o ancestry thy;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   212
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   213
fun morphism thy = #morphism o the_class_data thy;
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   214
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   215
fun these_intros thy =
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   216
  Graph.fold (fn (_, (data, _)) => insert Thm.eq_thm ((#intro o rep_class_data) data))
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   217
    (ClassData.get thy) [];
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   218
24836
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   219
fun these_operations thy =
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   220
  maps (#operations o the_class_data thy) o ancestry thy;
24657
185502d54c3d fixed wrong syntax treatment in class target
haftmann
parents: 24589
diff changeset
   221
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   222
fun print_classes thy =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   223
  let
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 24914
diff changeset
   224
    val ctxt = ProofContext.init thy;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   225
    val algebra = Sign.classes_of thy;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   226
    val arities =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   227
      Symtab.empty
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   228
      |> Symtab.fold (fn (tyco, arities) => fold (fn (class, _) =>
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   229
           Symtab.map_default (class, []) (insert (op =) tyco)) arities)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   230
             ((#arities o Sorts.rep_algebra) algebra);
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   231
    val the_arities = these o Symtab.lookup arities;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   232
    fun mk_arity class tyco =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   233
      let
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   234
        val Ss = Sorts.mg_domain algebra tyco [class];
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 24914
diff changeset
   235
      in Syntax.pretty_arity ctxt (tyco, Ss, [class]) end;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   236
    fun mk_param (c, ty) = Pretty.str (Sign.extern_const thy c ^ " :: "
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 24914
diff changeset
   237
      ^ setmp show_sorts false (Syntax.string_of_typ ctxt o Type.strip_sorts) ty);
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   238
    fun mk_entry class = (Pretty.block o Pretty.fbreaks o map_filter I) [
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   239
      (SOME o Pretty.str) ("class " ^ Sign.extern_class thy class ^ ":"),
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   240
      (SOME o Pretty.block) [Pretty.str "supersort: ",
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 24914
diff changeset
   241
        (Syntax.pretty_sort ctxt o Sign.minimize_sort thy o Sign.super_classes thy) class],
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   242
      if is_class thy class then (SOME o Pretty.str)
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   243
        ("locale: " ^ Locale.extern thy class) else NONE,
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   244
      ((fn [] => NONE | ps => (SOME o Pretty.block o Pretty.fbreaks)
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   245
          (Pretty.str "parameters:" :: ps)) o map mk_param
24930
cc2e0e8c81af renamed AxClass.get_definition to AxClass.get_info (again);
wenzelm
parents: 24920
diff changeset
   246
        o these o Option.map #params o try (AxClass.get_info thy)) class,
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   247
      (SOME o Pretty.block o Pretty.breaks) [
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   248
        Pretty.str "instances:",
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   249
        Pretty.list "" "" (map (mk_arity class) (the_arities class))
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   250
      ]
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   251
    ]
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   252
  in
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   253
    (Pretty.writeln o Pretty.chunks o separate (Pretty.str "")
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   254
      o map mk_entry o Sorts.all_classes) algebra
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   255
  end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   256
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   257
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   258
(* updaters *)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   259
25163
haftmann
parents: 25146
diff changeset
   260
fun add_class_data ((class, superclasses), (cs, base_sort, inst, phi, intro)) thy =
25002
haftmann
parents: 24981
diff changeset
   261
  let
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   262
    val operations = map (fn (v_ty as (_, ty), (c, _)) =>
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   263
      (c, (class, (ty, Free v_ty)))) cs;
25002
haftmann
parents: 24981
diff changeset
   264
    val cs = (map o pairself) fst cs;
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   265
    val add_class = Graph.new_node (class,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   266
        mk_class_data ((cs, base_sort, map (SOME o Const) inst, phi, intro), ([], operations)))
25002
haftmann
parents: 24981
diff changeset
   267
      #> fold (curry Graph.add_edge class) superclasses;
haftmann
parents: 24981
diff changeset
   268
  in
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   269
    ClassData.map add_class thy
25002
haftmann
parents: 24981
diff changeset
   270
  end;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   271
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   272
fun register_operation class (c, (t, some_def)) thy =
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   273
  let
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   274
    val base_sort = (#base_sort o the_class_data thy) class;
25239
3d6abdd10382 handling of notation in class target
haftmann
parents: 25210
diff changeset
   275
    val prep_typ = map_atyps
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   276
      (fn TVar (vi as (v, _), sort) => if Name.aT = v
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   277
        then TFree (v, base_sort) else TVar (vi, sort));
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   278
    val t' = map_types prep_typ t;
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   279
    val ty' = Term.fastype_of t';
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   280
  in
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   281
    thy
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   282
    |> (ClassData.map o Graph.map_node class o map_class_data o apsnd)
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   283
      (fn (defs, operations) =>
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   284
        (fold cons (the_list some_def) defs,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   285
          (c, (class, (ty', t'))) :: operations))
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   286
  end;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   287
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   288
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   289
(** rule calculation, tactics and methods **)
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   290
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   291
val class_prefix = Logic.const_of_class o Sign.base_name;
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   292
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   293
fun calculate_morphism class cs =
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   294
  let
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   295
    val subst_typ = Term.map_type_tfree (fn var as (v, sort) =>
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   296
      if v = Name.aT then TVar ((v, 0), [class]) else TVar ((v, 0), sort));
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   297
    fun subst_aterm (t as Free (v, ty)) = (case AList.lookup (op =) cs v
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   298
         of SOME (c, _) => Const (c, ty)
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   299
          | NONE => t)
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   300
      | subst_aterm t = t;
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   301
    val subst_term = map_aterms subst_aterm #> map_types subst_typ;
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   302
  in
25209
haftmann
parents: 25195
diff changeset
   303
    Morphism.term_morphism subst_term
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   304
    $> Morphism.typ_morphism subst_typ
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   305
  end;
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   306
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   307
fun class_intro thy class sups =
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   308
  let
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   309
    fun class_elim class =
25020
f1344290e420 (un)overload: full rewrite;
wenzelm
parents: 25010
diff changeset
   310
      case (#axioms o AxClass.get_info thy) class
f1344290e420 (un)overload: full rewrite;
wenzelm
parents: 25010
diff changeset
   311
       of [thm] => SOME (Drule.unconstrainTs thm)
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   312
        | [] => NONE;
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   313
    val pred_intro = case Locale.intros thy class
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   314
     of ([ax_intro], [intro]) => intro |> OF_LAST ax_intro |> SOME
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   315
      | ([intro], []) => SOME intro
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   316
      | ([], [intro]) => SOME intro
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   317
      | _ => NONE;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   318
    val pred_intro' = pred_intro
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   319
      |> Option.map (fn intro => intro OF map_filter class_elim sups);
24930
cc2e0e8c81af renamed AxClass.get_definition to AxClass.get_info (again);
wenzelm
parents: 24920
diff changeset
   320
    val class_intro = (#intro o AxClass.get_info thy) class;
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   321
    val raw_intro = case pred_intro'
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   322
     of SOME pred_intro => class_intro |> OF_LAST pred_intro
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   323
      | NONE => class_intro;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   324
    val sort = Sign.super_classes thy class;
24847
bc15dcaed517 replaced AxClass.param_tyvarname by Name.aT;
wenzelm
parents: 24836
diff changeset
   325
    val typ = TVar ((Name.aT, 0), sort);
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   326
    val defs = these_defs thy sups;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   327
  in
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   328
    raw_intro
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   329
    |> Drule.instantiate' [SOME (Thm.ctyp_of thy typ)] []
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   330
    |> strip_all_ofclass thy sort
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   331
    |> Thm.strip_shyps
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   332
    |> MetaSimplifier.rewrite_rule defs
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   333
    |> Drule.unconstrainTs
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   334
  end;
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   335
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   336
fun class_interpretation class facts defs thy =
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   337
  let
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   338
    val params = these_params thy [class];
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   339
    val inst = (#inst o the_class_data thy) class;
25020
f1344290e420 (un)overload: full rewrite;
wenzelm
parents: 25010
diff changeset
   340
    val tac = ALLGOALS (ProofContext.fact_tac facts);
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   341
    val prfx = class_prefix class;
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   342
  in
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   343
    thy
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   344
    |> fold_map (get_remove_global_constraint o fst o snd) params
25094
ba43514068fd Interpretation equations may have name and/or attribute.
ballarin
parents: 25083
diff changeset
   345
    ||> prove_interpretation tac ((false, prfx), []) (Locale.Locale class)
ba43514068fd Interpretation equations may have name and/or attribute.
ballarin
parents: 25083
diff changeset
   346
          (inst, map (fn def => (("", []), def)) defs)
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   347
    |-> (fn cs => fold (Sign.add_const_constraint o apsnd SOME) cs)
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   348
  end;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   349
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   350
fun intro_classes_tac facts st =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   351
  let
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   352
    val thy = Thm.theory_of_thm st;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   353
    val classes = Sign.all_classes thy;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   354
    val class_trivs = map (Thm.class_triv thy) classes;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   355
    val class_intros = these_intros thy;
24930
cc2e0e8c81af renamed AxClass.get_definition to AxClass.get_info (again);
wenzelm
parents: 24920
diff changeset
   356
    val axclass_intros = map_filter (try (#intro o AxClass.get_info thy)) classes;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   357
  in
25268
58146cb7bf44 more precise treatment of prove_subclass
haftmann
parents: 25239
diff changeset
   358
    Method.intros_tac (class_trivs @ class_intros @ axclass_intros) facts st
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   359
  end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   360
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   361
fun default_intro_classes_tac [] = intro_classes_tac []
24930
cc2e0e8c81af renamed AxClass.get_definition to AxClass.get_info (again);
wenzelm
parents: 24920
diff changeset
   362
  | default_intro_classes_tac _ = no_tac;
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   363
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   364
fun default_tac rules ctxt facts =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   365
  HEADGOAL (Method.some_rule_tac rules ctxt facts) ORELSE
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   366
    default_intro_classes_tac facts;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   367
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   368
val _ = Context.add_setup (Method.add_methods
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   369
 [("intro_classes", Method.no_args (Method.METHOD intro_classes_tac),
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   370
    "back-chain introduction rules of classes"),
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   371
  ("default", Method.thms_ctxt_args (Method.METHOD oo default_tac),
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   372
    "apply some intro/elim rule")]);
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   373
25195
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   374
fun subclass_rule thy (sub, sup) =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   375
  let
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   376
    val ctxt = Locale.init sub thy;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   377
    val ctxt_thy = ProofContext.init thy;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   378
    val props =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   379
      Locale.global_asms_of thy sup
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   380
      |> maps snd
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   381
      |> map (ObjectLogic.ensure_propT thy);
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   382
    fun tac { prems, context } =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   383
      Locale.intro_locales_tac true context prems
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   384
        ORELSE ALLGOALS assume_tac;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   385
  in
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   386
    Goal.prove_multi ctxt [] [] props tac
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   387
    |> map (Assumption.export false ctxt ctxt_thy)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   388
    |> Variable.export ctxt ctxt_thy
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   389
  end;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   390
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   391
fun prove_single_subclass (sub, sup) thms ctxt thy =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   392
  let
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   393
    val ctxt_thy = ProofContext.init thy;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   394
    val subclass_rule = Conjunction.intr_balanced thms
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   395
      |> Assumption.export false ctxt ctxt_thy
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   396
      |> singleton (Variable.export ctxt ctxt_thy);
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   397
    val sub_inst = Thm.ctyp_of thy (TVar ((Name.aT, 0), [sub]));
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   398
    val sub_ax = #axioms (AxClass.get_info thy sub);
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   399
    val classrel =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   400
      #intro (AxClass.get_info thy sup)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   401
      |> Drule.instantiate' [SOME sub_inst] []
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   402
      |> OF_LAST (subclass_rule OF sub_ax)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   403
      |> strip_all_ofclass thy (Sign.super_classes thy sup)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   404
      |> Thm.strip_shyps
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   405
  in
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   406
    thy
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   407
    |> AxClass.add_classrel classrel
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   408
    |> prove_interpretation_in (ALLGOALS (ProofContext.fact_tac thms))
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   409
         I (sub, Locale.Locale sup)
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   410
    |> ClassData.map (Graph.add_edge (sub, sup))
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   411
  end;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   412
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   413
fun prove_subclass (sub, sup) thms ctxt thy =
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   414
  let
25268
58146cb7bf44 more precise treatment of prove_subclass
haftmann
parents: 25239
diff changeset
   415
    val classes = ClassData.get thy;
58146cb7bf44 more precise treatment of prove_subclass
haftmann
parents: 25239
diff changeset
   416
    val is_sup = not o null o curry (Graph.irreducible_paths classes) sub;
58146cb7bf44 more precise treatment of prove_subclass
haftmann
parents: 25239
diff changeset
   417
    val supclasses = Graph.all_succs classes [sup] |> filter_out is_sup;
25195
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   418
    fun transform sup' = subclass_rule thy (sup, sup') |> map (fn thm => thm OF thms);
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   419
  in
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   420
    thy
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   421
    |> fold_rev (fn sup' => prove_single_subclass (sub, sup')
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   422
         (transform sup') ctxt) supclasses
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   423
 end;
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   424
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   425
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   426
(** classes and class target **)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   427
25002
haftmann
parents: 24981
diff changeset
   428
(* class context syntax *)
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   429
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   430
structure ClassSyntax = ProofDataFun(
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   431
  type T = {
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   432
    local_constraints: (string * typ) list,
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   433
    global_constraints: (string * typ) list,
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   434
    base_sort: sort,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   435
    operations: (string * (typ * term)) list,
25195
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   436
    unchecks: (term * term) list,
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   437
    passed: bool
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   438
  };
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   439
  fun init _ = {
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   440
    local_constraints = [],
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   441
    global_constraints = [],
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   442
    base_sort = [],
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   443
    operations = [],
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   444
    unchecks = [],
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   445
    passed = true
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   446
  };;
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   447
);
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   448
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   449
fun synchronize_syntax sups base_sort ctxt =
24914
95cda5dd58d5 added proper subclass concept; improved class target
haftmann
parents: 24901
diff changeset
   450
  let
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   451
    val thy = ProofContext.theory_of ctxt;
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   452
    fun subst_class_typ sort = map_atyps
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   453
      (fn TFree _ => TVar ((Name.aT, 0), sort) | ty' => ty');
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   454
    val operations = these_operations thy sups;
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   455
    val local_constraints =
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   456
      (map o apsnd) (subst_class_typ base_sort o fst o snd) operations;
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   457
    val global_constraints =
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   458
      (map o apsnd) (fn (class, (ty, _)) => subst_class_typ [class] ty) operations;
25318
c8352b38d47d synchronize_syntax: declare operations within the local scope of fixes/consts
wenzelm
parents: 25311
diff changeset
   459
    fun declare_const (c, _) =
c8352b38d47d synchronize_syntax: declare operations within the local scope of fixes/consts
wenzelm
parents: 25311
diff changeset
   460
      let val b = Sign.base_name c
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   461
      in Sign.intern_const thy b = c ? Variable.declare_const (b, c) end;
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   462
    val unchecks = map (fn (c, (_, (ty, t))) => (t, Const (c, ty))) operations;
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   463
  in
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   464
    ctxt
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   465
    |> fold declare_const local_constraints
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   466
    |> fold (ProofContext.add_const_constraint o apsnd SOME) local_constraints
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   467
    |> ClassSyntax.put {
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   468
        local_constraints = local_constraints,
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   469
        global_constraints = global_constraints,
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   470
        base_sort = base_sort,
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   471
        operations = (map o apsnd) snd operations,
25195
62638dcafe38 fixed syntax; truned code structure; added primitive subclass interface with consideraton of syntax etc.
haftmann
parents: 25163
diff changeset
   472
        unchecks = unchecks,
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   473
        passed = false
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   474
      }
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   475
  end;
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   476
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   477
fun refresh_syntax class ctxt =
25002
haftmann
parents: 24981
diff changeset
   478
  let
haftmann
parents: 24981
diff changeset
   479
    val thy = ProofContext.theory_of ctxt;
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   480
    val base_sort = (#base_sort o the_class_data thy) class;
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   481
  in synchronize_syntax [class] base_sort ctxt end;
24914
95cda5dd58d5 added proper subclass concept; improved class target
haftmann
parents: 24901
diff changeset
   482
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   483
val mark_passed = ClassSyntax.map
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   484
  (fn { local_constraints, global_constraints, base_sort, operations, unchecks, passed } =>
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   485
    { local_constraints = local_constraints, global_constraints = global_constraints,
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   486
      base_sort = base_sort, operations = operations, unchecks = unchecks, passed = true });
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   487
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   488
fun sort_term_check ts ctxt =
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   489
  let
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   490
    val { local_constraints, global_constraints, base_sort, operations, passed, ... } =
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   491
      ClassSyntax.get ctxt;
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   492
    fun check_improve (Const (c, ty)) = (case AList.lookup (op =) local_constraints c
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   493
         of SOME ty0 => (case try (Type.raw_match (ty0, ty)) Vartab.empty
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   494
             of SOME tyenv => (case Vartab.lookup tyenv (Name.aT, 0)
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   495
                 of SOME (_, TVar (tvar as (vi, _))) =>
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   496
                      if TypeInfer.is_param vi then cons tvar else I
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   497
                  | _ => I)
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   498
              | NONE => I)
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   499
          | NONE => I)
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   500
      | check_improve _ = I;
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   501
    val improvements = (fold o fold_aterms) check_improve ts [];
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   502
    val ts' = (map o map_types o map_atyps) (fn ty as TVar tvar =>
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   503
        if member (op =) improvements tvar
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   504
          then TFree (Name.aT, base_sort) else ty | ty => ty) ts;
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   505
    fun check t0 = Envir.expand_term (fn Const (c, ty) => (case AList.lookup (op =) operations c
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   506
         of SOME (ty0, t) =>
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   507
              if Type.typ_instance (ProofContext.tsig_of ctxt) (ty, ty0)
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   508
              then SOME (ty0, check t) else NONE
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   509
          | NONE => NONE)
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   510
      | _ => NONE) t0;
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   511
    val ts'' = map check ts';
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   512
  in if eq_list (op aconv) (ts, ts'') andalso passed then NONE
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   513
  else
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   514
    ctxt
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   515
    |> fold (ProofContext.add_const_constraint o apsnd SOME) global_constraints
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   516
    |> mark_passed
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   517
    |> pair ts''
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   518
    |> SOME
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   519
  end;
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   520
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   521
fun sort_term_uncheck ts ctxt =
25002
haftmann
parents: 24981
diff changeset
   522
  let
haftmann
parents: 24981
diff changeset
   523
    val thy = ProofContext.theory_of ctxt;
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   524
    val unchecks = (#unchecks o ClassSyntax.get) ctxt;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   525
    val ts' = map (Pattern.rewrite_term thy unchecks []) ts;
25060
17c313217998 Syntax.(un)check: explicit result option;
wenzelm
parents: 25038
diff changeset
   526
  in if eq_list (op aconv) (ts, ts') then NONE else SOME (ts', ctxt) end;
25002
haftmann
parents: 24981
diff changeset
   527
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   528
fun init_ctxt sups base_sort ctxt =
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   529
  ctxt
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   530
  |> Variable.declare_term
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   531
      (Logic.mk_type (TFree (Name.aT, base_sort)))
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   532
  |> synchronize_syntax sups base_sort
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   533
  |> Context.proof_map (
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   534
      Syntax.add_term_check 0 "class" sort_term_check
25103
haftmann
parents: 25096
diff changeset
   535
      #> Syntax.add_term_uncheck 0 "class" sort_term_uncheck)
24901
d3cbf79769b9 added first version of user-space type system for class target
haftmann
parents: 24847
diff changeset
   536
25311
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   537
fun init class thy =
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   538
  thy
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   539
  |> Locale.init class
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   540
  |> init_ctxt [class] ((#base_sort o the_class_data thy) class);
24914
95cda5dd58d5 added proper subclass concept; improved class target
haftmann
parents: 24901
diff changeset
   541
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   542
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   543
(* class definition *)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   544
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   545
local
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   546
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   547
fun gen_class_spec prep_class prep_expr process_expr thy raw_supclasses raw_includes_elems =
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   548
  let
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   549
    val supclasses = map (prep_class thy) raw_supclasses;
25209
haftmann
parents: 25195
diff changeset
   550
    val sups = filter (is_class thy) supclasses;
haftmann
parents: 25195
diff changeset
   551
    fun the_base_sort class = lookup_class_data thy class
haftmann
parents: 25195
diff changeset
   552
      |> Option.map #base_sort
haftmann
parents: 25195
diff changeset
   553
      |> the_default [class];
haftmann
parents: 25195
diff changeset
   554
    val base_sort = Sign.minimize_sort thy (maps the_base_sort supclasses);
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   555
    val supsort = Sign.minimize_sort thy supclasses;
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   556
    val suplocales = map Locale.Locale sups;
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   557
    val (raw_elems, includes) = fold_rev (fn Locale.Elem e => apfst (cons e)
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   558
      | Locale.Expr i => apsnd (cons (prep_expr thy i))) raw_includes_elems ([], []);
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   559
    val supexpr = Locale.Merge suplocales;
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   560
    val supparams = (map fst o Locale.parameters_of_expr thy) supexpr;
25002
haftmann
parents: 24981
diff changeset
   561
    val supconsts = AList.make (the o AList.lookup (op =) (these_params thy sups))
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   562
      (map fst supparams);
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   563
    val mergeexpr = Locale.Merge (suplocales @ includes);
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   564
    val constrain = Element.Constrains ((map o apsnd o map_atyps)
24847
bc15dcaed517 replaced AxClass.param_tyvarname by Name.aT;
wenzelm
parents: 24836
diff changeset
   565
      (fn TFree (_, sort) => TFree (Name.aT, sort)) supparams);
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   566
  in
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   567
    ProofContext.init thy
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   568
    |> Locale.cert_expr supexpr [constrain]
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   569
    |> snd
25344
00c2179db769 synchronize_syntax: improved declare_const (still inactive);
wenzelm
parents: 25326
diff changeset
   570
    |> init_ctxt sups base_sort
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   571
    |> process_expr Locale.empty raw_elems
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   572
    |> fst
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   573
    |> (fn elems => ((((sups, supconsts), (supsort, base_sort, mergeexpr)),
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   574
          (*FIXME*) if null includes then constrain :: elems else elems)))
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   575
  end;
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   576
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   577
val read_class_spec = gen_class_spec Sign.intern_class Locale.intern_expr Locale.read_expr;
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   578
val check_class_spec = gen_class_spec (K I) (K I) Locale.cert_expr;
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   579
24968
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   580
fun define_class_params (name, raw_superclasses) raw_consts raw_dep_axioms other_consts thy =
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   581
  let
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   582
    val superclasses = map (Sign.certify_class thy) raw_superclasses;
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   583
    val consts = (map o apfst o apsnd) (Sign.certify_typ thy) raw_consts;
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   584
    fun add_const ((c, ty), syn) =
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   585
      Sign.declare_const [] (c, Type.strip_sorts ty, syn) #>> Term.dest_Const;
24968
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   586
    fun mk_axioms cs thy =
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   587
      raw_dep_axioms thy cs
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   588
      |> (map o apsnd o map) (Sign.cert_prop thy)
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   589
      |> rpair thy;
25002
haftmann
parents: 24981
diff changeset
   590
    fun constrain_typs class = (map o apsnd o Term.map_type_tfree)
haftmann
parents: 24981
diff changeset
   591
      (fn (v, _) => TFree (v, [class]))
24968
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   592
  in
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   593
    thy
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   594
    |> Sign.add_path (Logic.const_of_class name)
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   595
    |> fold_map add_const consts
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   596
    ||> Sign.restore_naming thy
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   597
    |-> (fn cs => mk_axioms cs
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   598
    #-> (fn axioms_prop => AxClass.define_class (name, superclasses)
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   599
           (map fst cs @ other_consts) axioms_prop
25002
haftmann
parents: 24981
diff changeset
   600
    #-> (fn class => `(fn _ => constrain_typs class cs)
haftmann
parents: 24981
diff changeset
   601
    #-> (fn cs' => `(fn thy => AxClass.get_info thy class)
haftmann
parents: 24981
diff changeset
   602
    #-> (fn {axioms, ...} => fold (Sign.add_const_constraint o apsnd SOME) cs'
haftmann
parents: 24981
diff changeset
   603
    #> pair (class, (cs', axioms)))))))
24968
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   604
  end;
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   605
25002
haftmann
parents: 24981
diff changeset
   606
fun gen_class prep_spec prep_param bname
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   607
    raw_supclasses raw_includes_elems raw_other_consts thy =
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   608
  let
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   609
    val class = Sign.full_name thy bname;
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   610
    val (((sups, supconsts), (supsort, base_sort, mergeexpr)), elems_syn) =
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   611
      prep_spec thy raw_supclasses raw_includes_elems;
24968
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   612
    val other_consts = map (tap (Sign.the_const_type thy) o prep_param thy) raw_other_consts;
25163
haftmann
parents: 25146
diff changeset
   613
    fun mk_inst class cs =
haftmann
parents: 25146
diff changeset
   614
      (map o apsnd o Term.map_type_tfree) (fn (v, _) => TFree (v, [class])) cs;
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   615
    fun fork_syntax (Element.Fixes xs) =
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   616
          fold_map (fn (c, ty, syn) => cons (c, syn) #> pair (c, ty, NoSyn)) xs
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   617
          #>> Element.Fixes
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   618
      | fork_syntax x = pair x;
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   619
    val (elems, global_syn) = fold_map fork_syntax elems_syn [];
25326
e417a7236125 refined Variable.declare_const;
wenzelm
parents: 25318
diff changeset
   620
    fun globalize (c, ty) =
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   621
      ((c, Term.map_type_tfree (K (TFree (Name.aT, base_sort))) ty),
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   622
        (the_default NoSyn o AList.lookup (op =) global_syn) c);
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   623
    fun extract_params thy =
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   624
      let
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   625
        val params = map fst (Locale.parameters_of thy class);
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   626
      in
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   627
        (params, (map globalize o snd o chop (length supconsts)) params)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   628
      end;
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   629
    fun extract_assumes params thy cs =
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   630
      let
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   631
        val consts = supconsts @ (map (fst o fst) params ~~ cs);
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   632
        fun subst (Free (c, ty)) =
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   633
              Const ((fst o the o AList.lookup (op =) consts) c, ty)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   634
          | subst t = t;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   635
        fun prep_asm ((name, atts), ts) =
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   636
          ((Sign.base_name name, map (Attrib.attribute_i thy) atts),
24589
d3fca349736c clarified class interfaces and internals
haftmann
parents: 24435
diff changeset
   637
            (map o map_aterms) subst ts);
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   638
      in
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   639
        Locale.global_asms_of thy class
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   640
        |> map prep_asm
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   641
      end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   642
  in
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   643
    thy
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   644
    |> Locale.add_locale_i (SOME "") bname mergeexpr elems
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   645
    |> snd
25311
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   646
    |> ProofContext.theory_of
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   647
    |> `extract_params
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   648
    |-> (fn (all_params, params) =>
24968
f9bafc868847 replaced Sign.add_consts_authentic by Sign.declare_const;
wenzelm
parents: 24949
diff changeset
   649
        define_class_params (bname, supsort) params
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   650
          (extract_assumes params) other_consts
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   651
      #-> (fn (_, (consts, axioms)) =>
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   652
        `(fn thy => class_intro thy class sups)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   653
      #-> (fn class_intro =>
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   654
        PureThy.note_thmss_qualified "" (NameSpace.append class classN)
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   655
          [((introN, []), [([class_intro], [])])]
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   656
      #-> (fn [(_, [class_intro])] =>
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   657
        add_class_data ((class, sups),
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   658
          (map fst params ~~ consts, base_sort,
25163
haftmann
parents: 25146
diff changeset
   659
            mk_inst class (map snd supconsts @ consts),
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   660
              calculate_morphism class (supconsts @ (map (fst o fst) params ~~ consts)), class_intro))
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   661
      #> class_interpretation class axioms []
25311
aa750e3a581c Class.init now similiar to Locale.init
haftmann
parents: 25268
diff changeset
   662
      ))))
25268
58146cb7bf44 more precise treatment of prove_subclass
haftmann
parents: 25239
diff changeset
   663
    |> init class
25038
522abf8a5f87 canonical interpretation interface
haftmann
parents: 25024
diff changeset
   664
    |> pair class
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   665
  end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   666
25326
e417a7236125 refined Variable.declare_const;
wenzelm
parents: 25318
diff changeset
   667
fun read_const thy = #1 o Term.dest_Const o ProofContext.read_const (ProofContext.init thy);
e417a7236125 refined Variable.declare_const;
wenzelm
parents: 25318
diff changeset
   668
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   669
in
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   670
25326
e417a7236125 refined Variable.declare_const;
wenzelm
parents: 25318
diff changeset
   671
val class_cmd = gen_class read_class_spec read_const;
24748
ee0a0eb6b738 proper syntax during class specification
haftmann
parents: 24731
diff changeset
   672
val class = gen_class check_class_spec (K I);
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   673
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   674
end; (*local*)
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   675
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   676
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   677
(* class target *)
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   678
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   679
fun logical_const class pos ((c, mx), dict) thy =
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   680
  let
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   681
    val prfx = class_prefix class;
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   682
    val thy' = thy |> Sign.add_path prfx;
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   683
    val phi = morphism thy' class;
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   684
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   685
    val c' = Sign.full_name thy' c;
25239
3d6abdd10382 handling of notation in class target
haftmann
parents: 25210
diff changeset
   686
    val dict' = Morphism.term phi dict;
3d6abdd10382 handling of notation in class target
haftmann
parents: 25210
diff changeset
   687
    val dict_def = map_types Logic.unvarifyT dict';
3d6abdd10382 handling of notation in class target
haftmann
parents: 25210
diff changeset
   688
    val ty' = Term.fastype_of dict_def;
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   689
    val ty'' = Type.strip_sorts ty';
25239
3d6abdd10382 handling of notation in class target
haftmann
parents: 25210
diff changeset
   690
    val def_eq = Logic.mk_equals (Const (c', ty'), dict_def);
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   691
  in
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   692
    thy'
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   693
    |> Sign.declare_const pos (c, ty'', mx) |> snd
25518
00d5cc16e891 interface for unchecked definitions
haftmann
parents: 25514
diff changeset
   694
    |> Thm.add_def false false (c, def_eq)
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   695
    |>> Thm.symmetric
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   696
    |-> (fn def => class_interpretation class [def] [Thm.prop_of def]
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   697
          #> register_operation class (c', (dict', SOME (Thm.varifyT def))))
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   698
    |> Sign.restore_naming thy
25083
765528b4b419 improved class syntax
haftmann
parents: 25066
diff changeset
   699
    |> Sign.add_const_constraint (c', SOME ty')
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   700
  end;
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   701
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   702
fun syntactic_const class prmode pos ((c, mx), rhs) thy =
24836
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   703
  let
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   704
    val prfx = class_prefix class;
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   705
    val thy' = thy |> Sign.add_path prfx;
25062
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   706
    val phi = morphism thy class;
af5ef0d4d655 global class syntax
haftmann
parents: 25060
diff changeset
   707
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   708
    val c' = Sign.full_name thy' c;
25146
c2a41f31cacb tuned abbreviations in class context
haftmann
parents: 25104
diff changeset
   709
    val rews = map (Logic.dest_equals o Thm.prop_of) (these_defs thy' [class])
c2a41f31cacb tuned abbreviations in class context
haftmann
parents: 25104
diff changeset
   710
    val rhs' = (Pattern.rewrite_term thy rews [] o Morphism.term phi) rhs;
25239
3d6abdd10382 handling of notation in class target
haftmann
parents: 25210
diff changeset
   711
    val ty' = Logic.unvarifyT (Term.fastype_of rhs');
24836
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   712
  in
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   713
    thy'
25146
c2a41f31cacb tuned abbreviations in class context
haftmann
parents: 25104
diff changeset
   714
    |> Sign.add_abbrev (#1 prmode) pos (c, map_types Type.strip_sorts rhs') |> snd
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   715
    |> Sign.add_const_constraint (c', SOME ty')
25024
0615bb9955dd added is_class;
wenzelm
parents: 25020
diff changeset
   716
    |> Sign.notation true prmode [(Const (c', ty'), mx)]
25368
f12613fda79d proper implementation of check phase; non-qualified names for class operations
haftmann
parents: 25344
diff changeset
   717
    |> register_operation class (c', (rhs', NONE))
25096
b8950f7cf92e clarified abbreviations in class context
haftmann
parents: 25094
diff changeset
   718
    |> Sign.restore_naming thy
24836
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   719
  end;
dab06e93ec28 intermediate cleanup
haftmann
parents: 24770
diff changeset
   720
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   721
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   722
(** instantiation target **)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   723
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   724
(* bookkeeping *)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   725
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   726
datatype instantiation = Instantiation of {
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   727
  arities: string list * sort list * sort,
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   728
  params: ((string * string) * (string * typ)) list
25574
016f677ad7b8 declaration of instance parameter names
haftmann
parents: 25536
diff changeset
   729
    (*(instantiation const, type constructor), (local instantiation parameter, typ)*)
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   730
}
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   731
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   732
structure Instantiation = ProofDataFun
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   733
(
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   734
  type T = instantiation
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   735
  fun init _ = Instantiation { arities = ([], [], []), params = [] };
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   736
);
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   737
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   738
fun mk_instantiation (arities, params) =
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   739
  Instantiation { arities = arities, params = params };
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   740
fun get_instantiation lthy = case Instantiation.get (LocalTheory.target_of lthy)
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   741
 of Instantiation data => data;
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   742
fun map_instantiation f = (LocalTheory.target o Instantiation.map)
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   743
  (fn Instantiation { arities, params } => mk_instantiation (f (arities, params)));
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   744
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   745
fun the_instantiation lthy = case get_instantiation lthy
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   746
 of { arities = ([], [], []), ... } => error "No instantiation target"
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   747
  | data => data;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   748
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   749
val instantiation_params = #params o get_instantiation;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   750
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   751
fun instantiation_param lthy v = instantiation_params lthy
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   752
  |> find_first (fn (_, (v', _)) => v = v')
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   753
  |> Option.map (fst o fst);
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   754
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   755
fun confirm_declaration c = (map_instantiation o apsnd)
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   756
  (filter_out (fn (_, (c', _)) => c' = c));
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   757
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   758
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   759
(* syntax *)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   760
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   761
fun subst_param thy params = map_aterms (fn t as Const (c, ty) =>
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   762
    (case AxClass.inst_tyco_of thy (c, ty)
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   763
     of SOME tyco => (case AList.lookup (op =) params (c, tyco)
01753a944433 improved
haftmann
parents: 25518
diff changeset
   764
         of SOME v_ty => Free v_ty
01753a944433 improved
haftmann
parents: 25518
diff changeset
   765
          | NONE => t)
01753a944433 improved
haftmann
parents: 25518
diff changeset
   766
      | NONE => t)
01753a944433 improved
haftmann
parents: 25518
diff changeset
   767
  | t => t);
01753a944433 improved
haftmann
parents: 25518
diff changeset
   768
01753a944433 improved
haftmann
parents: 25518
diff changeset
   769
fun prep_spec lthy =
01753a944433 improved
haftmann
parents: 25518
diff changeset
   770
  let
01753a944433 improved
haftmann
parents: 25518
diff changeset
   771
    val thy = ProofContext.theory_of lthy;
01753a944433 improved
haftmann
parents: 25518
diff changeset
   772
    val params = instantiation_params lthy;
01753a944433 improved
haftmann
parents: 25518
diff changeset
   773
  in subst_param thy params end;
01753a944433 improved
haftmann
parents: 25518
diff changeset
   774
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   775
fun inst_term_check ts lthy =
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   776
  let
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   777
    val params = instantiation_params lthy;
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   778
    val tsig = ProofContext.tsig_of lthy;
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   779
    val thy = ProofContext.theory_of lthy;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   780
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   781
    fun check_improve (Const (c, ty)) = (case AxClass.inst_tyco_of thy (c, ty)
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   782
         of SOME tyco => (case AList.lookup (op =) params (c, tyco)
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25485
diff changeset
   783
             of SOME (_, ty') => perhaps (try (Type.typ_match tsig (ty, ty')))
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   784
              | NONE => I)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   785
          | NONE => I)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   786
      | check_improve _ = I;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   787
    val improvement = (fold o fold_aterms) check_improve ts Vartab.empty;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   788
    val ts' = (map o map_types) (Envir.typ_subst_TVars improvement) ts;
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   789
    val ts'' = map (subst_param thy params) ts';
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   790
  in if eq_list (op aconv) (ts, ts'') then NONE else SOME (ts'', lthy) end;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   791
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   792
fun inst_term_uncheck ts lthy =
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   793
  let
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   794
    val params = instantiation_params lthy;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   795
    val ts' = (map o map_aterms) (fn t as Free (v, ty) =>
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   796
       (case get_first (fn ((c, _), (v', _)) => if v = v' then SOME c else NONE) params
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   797
         of SOME c => Const (c, ty)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   798
          | NONE => t)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   799
      | t => t) ts;
25514
4b508bb31a6c first working version of instance target
haftmann
parents: 25502
diff changeset
   800
  in if eq_list (op aconv) (ts, ts') then NONE else SOME (ts', lthy) end;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   801
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   802
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   803
(* target *)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   804
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   805
val sanatize_name = (*FIXME*)
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   806
  let
25574
016f677ad7b8 declaration of instance parameter names
haftmann
parents: 25536
diff changeset
   807
    fun is_valid s = Symbol.is_ascii_letter s orelse Symbol.is_ascii_digit s
016f677ad7b8 declaration of instance parameter names
haftmann
parents: 25536
diff changeset
   808
      orelse s = "'" orelse s = "_";
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   809
    val is_junk = not o is_valid andf Symbol.is_regular;
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   810
    val junk = Scan.many is_junk;
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   811
    val scan_valids = Symbol.scanner "Malformed input"
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   812
      ((junk |--
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   813
        (Scan.optional (Scan.one Symbol.is_ascii_letter) "x" ^^ (Scan.many is_valid >> implode)
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   814
        --| junk))
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   815
      -- Scan.repeat ((Scan.many1 is_valid >> implode) --| junk) >> op ::);
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   816
  in
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   817
    explode #> scan_valids #> implode
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   818
  end;
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   819
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   820
fun init_instantiation (tycos, sorts, sort) thy =
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   821
  let
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   822
    val _ = if null tycos then error "At least one arity must be given" else ();
01753a944433 improved
haftmann
parents: 25518
diff changeset
   823
    val _ = map (the_class_data thy) sort;
01753a944433 improved
haftmann
parents: 25518
diff changeset
   824
    val vs = map TFree (Name.names Name.context Name.aT sorts);
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   825
    fun type_name "*" = "prod"
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   826
      | type_name "+" = "sum"
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   827
      | type_name s = sanatize_name (NameSpace.base s); (*FIXME*)
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   828
    fun get_param tyco (param, (c, ty)) = if can (AxClass.param_of_inst thy) (c, tyco)
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   829
      then NONE else SOME ((AxClass.unoverload_const thy (c, ty), tyco),
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   830
        (param ^ "_" ^ type_name tyco, map_atyps (K (Type (tyco, vs))) ty));
01753a944433 improved
haftmann
parents: 25518
diff changeset
   831
    val params = map_product get_param tycos (these_params thy sort) |> map_filter I;
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   832
  in
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   833
    thy
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   834
    |> ProofContext.init
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   835
    |> Instantiation.put (mk_instantiation ((tycos, sorts, sort), params))
01753a944433 improved
haftmann
parents: 25518
diff changeset
   836
    |> fold (Variable.declare_term o Logic.mk_type) vs
25574
016f677ad7b8 declaration of instance parameter names
haftmann
parents: 25536
diff changeset
   837
    |> fold (Variable.declare_names o Free o snd) params
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   838
    |> fold (fn tyco => ProofContext.add_arity (tyco, sorts, sort)) tycos
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   839
    |> Context.proof_map (
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   840
        Syntax.add_term_check 0 "instance" inst_term_check
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   841
        #> Syntax.add_term_uncheck 0 "instance" inst_term_uncheck)
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   842
  end;
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   843
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   844
fun gen_instantiation_instance do_proof after_qed lthy =
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   845
  let
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   846
    val (tycos, sorts, sort) = (#arities o the_instantiation) lthy;
01753a944433 improved
haftmann
parents: 25518
diff changeset
   847
    val arities_proof = maps (fn tyco => Logic.mk_arities (tyco, sorts, sort)) tycos;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   848
    fun after_qed' results =
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   849
      LocalTheory.theory (fold (AxClass.add_arity o Thm.varifyT) results)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   850
      #> after_qed;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   851
  in
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   852
    lthy
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   853
    |> do_proof after_qed' arities_proof
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   854
  end;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   855
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   856
val instantiation_instance = gen_instantiation_instance (fn after_qed => fn ts =>
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   857
  Proof.theorem_i NONE (after_qed o map the_single) (map (fn t => [(t, [])]) ts));
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   858
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   859
fun prove_instantiation_instance tac = gen_instantiation_instance (fn after_qed =>
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25485
diff changeset
   860
  fn ts => fn lthy => after_qed (map (fn t => Goal.prove lthy [] [] t
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 25485
diff changeset
   861
    (fn {context, ...} => tac context)) ts) lthy) I;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   862
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   863
fun conclude_instantiation lthy =
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   864
  let
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   865
    val { arities, params } = the_instantiation lthy;
25536
01753a944433 improved
haftmann
parents: 25518
diff changeset
   866
    val (tycos, sorts, sort) = arities;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   867
    val thy = ProofContext.theory_of lthy;
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   868
    val _ = map (fn tyco => if Sign.of_sort thy
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   869
        (Type (tyco, map TFree (Name.names Name.context Name.aT sorts)), sort)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   870
      then () else error ("Missing instance proof for type " ^ quote (Sign.extern_type thy tyco)))
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   871
        tycos;
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25574
diff changeset
   872
  in lthy end;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25368
diff changeset
   873
24218
fbf1646b267c ClassPackage renamed to Class
haftmann
parents:
diff changeset
   874
end;