src/Pure/theory.ML
author haftmann
Tue Sep 18 07:46:00 2007 +0200 (2007-09-18 ago)
changeset 24626 85eceef2edc7
parent 24199 8be734b5f59f
child 24666 9885a86f14a8
permissions -rw-r--r--
introduced generic concepts for theory interpretators
paulson@1526
     1
(*  Title:      Pure/theory.ML
paulson@1526
     2
    ID:         $Id$
paulson@1526
     3
    Author:     Lawrence C Paulson and Markus Wenzel
paulson@1526
     4
wenzelm@16443
     5
Logical theory content: axioms, definitions, oracles.
paulson@1526
     6
*)
wenzelm@16291
     7
wenzelm@3767
     8
signature BASIC_THEORY =
wenzelm@3767
     9
sig
wenzelm@16443
    10
  val eq_thy: theory * theory -> bool
wenzelm@3996
    11
  val subthy: theory * theory -> bool
wenzelm@3767
    12
end
wenzelm@3767
    13
wenzelm@3767
    14
signature THEORY =
wenzelm@3767
    15
sig
wenzelm@3767
    16
  include BASIC_THEORY
wenzelm@16443
    17
  include SIGN_THEORY
wenzelm@22684
    18
  val parents_of: theory -> theory list
wenzelm@22684
    19
  val ancestors_of: theory -> theory list
wenzelm@16495
    20
  val begin_theory: string -> theory list -> theory
wenzelm@16495
    21
  val end_theory: theory -> theory
wenzelm@16495
    22
  val checkpoint: theory -> theory
wenzelm@16495
    23
  val copy: theory -> theory
wenzelm@22684
    24
  val rep_theory: theory ->
wenzelm@22684
    25
   {axioms: term NameSpace.table,
wenzelm@22684
    26
    defs: Defs.T,
wenzelm@22684
    27
    oracles: ((theory * Object.T -> term) * stamp) NameSpace.table}
wenzelm@16443
    28
  val axiom_space: theory -> NameSpace.T
wenzelm@22684
    29
  val axiom_table: theory -> term Symtab.table
wenzelm@16443
    30
  val oracle_space: theory -> NameSpace.T
wenzelm@22684
    31
  val oracle_table: theory -> ((theory * Object.T -> term) * stamp) Symtab.table
wenzelm@16339
    32
  val axioms_of: theory -> (string * term) list
wenzelm@16339
    33
  val all_axioms_of: theory -> (string * term) list
wenzelm@17706
    34
  val defs_of : theory -> Defs.T
wenzelm@24137
    35
  val check_thy: theory -> theory_ref
wenzelm@16443
    36
  val deref: theory_ref -> theory
wenzelm@23600
    37
  val merge: theory * theory -> theory
wenzelm@23600
    38
  val merge_refs: theory_ref * theory_ref -> theory_ref
wenzelm@23600
    39
  val merge_list: theory list -> theory
wenzelm@16443
    40
  val requires: theory -> string -> string -> unit
wenzelm@16443
    41
  val assert_super: theory -> theory -> theory
wenzelm@22684
    42
  val cert_axm: theory -> string * term -> string * term
wenzelm@22684
    43
  val read_axm: theory -> string * string -> string * term
wenzelm@3996
    44
  val add_axioms: (bstring * string) list -> theory -> theory
wenzelm@3996
    45
  val add_axioms_i: (bstring * term) list -> theory -> theory
wenzelm@19708
    46
  val add_deps: string -> string * typ -> (string * typ) list -> theory -> theory
wenzelm@19630
    47
  val add_defs: bool -> bool -> (bstring * string) list -> theory -> theory
wenzelm@19630
    48
  val add_defs_i: bool -> bool -> (bstring * term) list -> theory -> theory
wenzelm@16443
    49
  val add_finals: bool -> string list -> theory -> theory
wenzelm@16443
    50
  val add_finals_i: bool -> term list -> theory -> theory
wenzelm@16443
    51
  val add_oracle: bstring * (theory * Object.T -> term) -> theory -> theory
wenzelm@16495
    52
end
paulson@1526
    53
haftmann@24626
    54
signature THEORY_INTERPRETATOR =
haftmann@24626
    55
sig
haftmann@24626
    56
  type T
haftmann@24626
    57
  type interpretator = T list -> theory -> theory
haftmann@24626
    58
  val add_those: T list -> theory -> theory
haftmann@24626
    59
  val all_those: theory -> T list
haftmann@24626
    60
  val add_interpretator: interpretator -> theory -> theory
haftmann@24626
    61
  val init: theory -> theory
haftmann@24626
    62
end;
haftmann@24626
    63
haftmann@24626
    64
signature THEORY_INTERPRETATOR_KEY =
haftmann@24626
    65
sig
haftmann@24626
    66
  type T
haftmann@24626
    67
  val eq: T * T -> bool
haftmann@24626
    68
end;
haftmann@24626
    69
haftmann@24626
    70
structure Theory =
wenzelm@16443
    71
struct
wenzelm@16443
    72
wenzelm@19708
    73
haftmann@24626
    74
(** datatype thy **)
haftmann@24626
    75
haftmann@24626
    76
datatype thy = Thy of
haftmann@24626
    77
 {axioms: term NameSpace.table,
haftmann@24626
    78
  defs: Defs.T,
haftmann@24626
    79
  oracles: ((theory * Object.T -> term) * stamp) NameSpace.table,
haftmann@24626
    80
  consolidate: theory -> theory};
haftmann@24626
    81
haftmann@24626
    82
fun make_thy (axioms, defs, oracles, consolidate) =
haftmann@24626
    83
  Thy {axioms = axioms, defs = defs, oracles = oracles, consolidate = consolidate};
haftmann@24626
    84
haftmann@24626
    85
fun err_dup_axm dup = error ("Duplicate axiom: " ^ quote dup);
haftmann@24626
    86
fun err_dup_ora dup = error ("Duplicate oracle: " ^ quote dup);
haftmann@24626
    87
haftmann@24626
    88
structure ThyData = TheoryDataFun
haftmann@24626
    89
(
haftmann@24626
    90
  type T = thy;
haftmann@24626
    91
  val empty = make_thy (NameSpace.empty_table, Defs.empty, NameSpace.empty_table, I);
haftmann@24626
    92
  val copy = I;
haftmann@24626
    93
haftmann@24626
    94
  fun extend (Thy {axioms, defs, oracles, consolidate}) =
haftmann@24626
    95
    make_thy (NameSpace.empty_table, defs, oracles, consolidate);
haftmann@24626
    96
haftmann@24626
    97
  fun merge pp (thy1, thy2) =
haftmann@24626
    98
    let
haftmann@24626
    99
      val Thy {axioms = _, defs = defs1, oracles = oracles1,
haftmann@24626
   100
        consolidate = consolidate1} = thy1;
haftmann@24626
   101
      val Thy {axioms = _, defs = defs2, oracles = oracles2,
haftmann@24626
   102
        consolidate = consolidate2} = thy2;
haftmann@24626
   103
haftmann@24626
   104
      val axioms = NameSpace.empty_table;
haftmann@24626
   105
      val defs = Defs.merge pp (defs1, defs2);
haftmann@24626
   106
      val oracles = NameSpace.merge_tables (eq_snd (op =)) (oracles1, oracles2)
haftmann@24626
   107
        handle Symtab.DUP dup => err_dup_ora dup;
haftmann@24626
   108
      val consolidate = consolidate1 #> consolidate2;
haftmann@24626
   109
    in make_thy (axioms, defs, oracles, consolidate) end;
haftmann@24626
   110
);
haftmann@24626
   111
haftmann@24626
   112
fun rep_theory thy = ThyData.get thy |> (fn Thy {axioms, defs, oracles, ...} =>
haftmann@24626
   113
  {axioms = axioms, defs = defs, oracles = oracles});
haftmann@24626
   114
haftmann@24626
   115
fun map_thy f = ThyData.map (fn (Thy {axioms, defs, oracles, consolidate}) =>
haftmann@24626
   116
  make_thy (f (axioms, defs, oracles, consolidate)));
haftmann@24626
   117
haftmann@24626
   118
fun map_axioms f = map_thy
haftmann@24626
   119
  (fn (axioms, defs, oracles, consolidate) => (f axioms, defs, oracles, consolidate));
haftmann@24626
   120
fun map_defs f = map_thy
haftmann@24626
   121
  (fn (axioms, defs, oracles, consolidate) => (axioms, f defs, oracles, consolidate));
haftmann@24626
   122
fun map_oracles f = map_thy
haftmann@24626
   123
  (fn (axioms, defs, oracles, consolidate) => (axioms, defs, f oracles, consolidate));
haftmann@24626
   124
haftmann@24626
   125
haftmann@24626
   126
(* basic operations *)
haftmann@24626
   127
haftmann@24626
   128
val axiom_space = #1 o #axioms o rep_theory;
haftmann@24626
   129
val axiom_table = #2 o #axioms o rep_theory;
haftmann@24626
   130
haftmann@24626
   131
val oracle_space = #1 o #oracles o rep_theory;
haftmann@24626
   132
val oracle_table = #2 o #oracles o rep_theory;
haftmann@24626
   133
haftmann@24626
   134
val axioms_of = Symtab.dest o #2 o #axioms o rep_theory;
haftmann@24626
   135
haftmann@24626
   136
val defs_of = #defs o rep_theory;
haftmann@24626
   137
haftmann@24626
   138
fun requires thy name what =
haftmann@24626
   139
  if Context.exists_name name thy then ()
haftmann@24626
   140
  else error ("Require theory " ^ quote name ^ " as an ancestor for " ^ what);
haftmann@24626
   141
haftmann@24626
   142
haftmann@24626
   143
(* interpretators *)
haftmann@24626
   144
haftmann@24626
   145
fun add_consolidate f = map_thy
haftmann@24626
   146
  (fn (axioms, defs, oracles, consolidate) => (axioms, defs, oracles, consolidate #> f));
haftmann@24626
   147
haftmann@24626
   148
fun consolidate thy =
haftmann@24626
   149
  let
haftmann@24626
   150
    val Thy {consolidate, ...} = ThyData.get thy;
haftmann@24626
   151
  in
haftmann@24626
   152
    thy |> consolidate
haftmann@24626
   153
  end;
haftmann@24626
   154
haftmann@24626
   155
wenzelm@16443
   156
(** type theory **)
wenzelm@16443
   157
wenzelm@16443
   158
(* context operations *)
wenzelm@16443
   159
wenzelm@16443
   160
val eq_thy = Context.eq_thy;
wenzelm@16443
   161
val subthy = Context.subthy;
paulson@1526
   162
haftmann@24626
   163
fun assert_super thy1 thy2 =
haftmann@24626
   164
  if subthy (thy1, thy2) then thy2
haftmann@24626
   165
  else raise THEORY ("Not a super theory", [thy1, thy2]);
haftmann@24626
   166
wenzelm@16443
   167
val parents_of = Context.parents_of;
wenzelm@16443
   168
val ancestors_of = Context.ancestors_of;
wenzelm@16443
   169
wenzelm@24137
   170
val check_thy = Context.check_thy;
wenzelm@16443
   171
val deref = Context.deref;
wenzelm@16443
   172
val merge = Context.merge;
wenzelm@16443
   173
val merge_refs = Context.merge_refs;
wenzelm@16443
   174
wenzelm@23600
   175
fun merge_list [] = raise THEORY ("Empty merge of theories", [])
wenzelm@21608
   176
  | merge_list (thy :: thys) = Library.foldl merge (thy, thys);
wenzelm@21608
   177
haftmann@24626
   178
val begin_theory = Sign.local_path o consolidate oo Context.begin_thy Sign.pp;
wenzelm@16495
   179
val end_theory = Context.finish_thy;
wenzelm@16495
   180
val checkpoint = Context.checkpoint_thy;
wenzelm@16495
   181
val copy = Context.copy_thy;
wenzelm@16495
   182
wenzelm@16443
   183
wenzelm@16443
   184
(* signature operations *)
wenzelm@16443
   185
wenzelm@16443
   186
structure SignTheory: SIGN_THEORY = Sign;
wenzelm@16443
   187
open SignTheory;
wenzelm@16443
   188
wenzelm@2206
   189
wenzelm@3996
   190
haftmann@24626
   191
(** axioms **)
paulson@1526
   192
wenzelm@19482
   193
fun all_axioms_of thy = maps axioms_of (thy :: ancestors_of thy);
wenzelm@16339
   194
wenzelm@3814
   195
paulson@1526
   196
(* prepare axioms *)
paulson@1526
   197
wenzelm@18678
   198
fun err_in_axm msg name =
wenzelm@18678
   199
  cat_error msg ("The error(s) above occurred in axiom " ^ quote name);
paulson@1526
   200
wenzelm@16443
   201
fun cert_axm thy (name, raw_tm) =
paulson@1526
   202
  let
wenzelm@18968
   203
    val (t, T, _) = Sign.certify_prop thy raw_tm
wenzelm@2979
   204
      handle TYPE (msg, _, _) => error msg
wenzelm@16291
   205
        | TERM (msg, _) => error msg;
paulson@1526
   206
  in
wenzelm@9537
   207
    Term.no_dummy_patterns t handle TERM (msg, _) => error msg;
wenzelm@18968
   208
    (name, Sign.no_vars (Sign.pp thy) t)
wenzelm@9629
   209
  end;
paulson@1526
   210
wenzelm@22684
   211
fun read_axm thy (name, str) =
wenzelm@22689
   212
  cert_axm thy (name, Sign.read_prop thy str)
wenzelm@22689
   213
    handle ERROR msg => err_in_axm msg name;
paulson@1526
   214
paulson@1526
   215
wenzelm@16443
   216
(* add_axioms(_i) *)
paulson@1526
   217
wenzelm@16291
   218
local
wenzelm@16291
   219
wenzelm@16443
   220
fun gen_add_axioms prep_axm raw_axms thy = thy |> map_axioms (fn axioms =>
paulson@1526
   221
  let
wenzelm@16991
   222
    val axms = map (apsnd (Compress.term thy o Logic.varify) o prep_axm thy) raw_axms;
haftmann@23086
   223
    val axioms' = NameSpace.extend_table (Sign.naming_of thy) axms axioms
wenzelm@23655
   224
      handle Symtab.DUP dup => err_dup_axm dup;
wenzelm@16443
   225
  in axioms' end);
paulson@1526
   226
wenzelm@16291
   227
in
wenzelm@16291
   228
wenzelm@16291
   229
val add_axioms = gen_add_axioms read_axm;
wenzelm@16291
   230
val add_axioms_i = gen_add_axioms cert_axm;
wenzelm@16291
   231
wenzelm@16291
   232
end;
paulson@1526
   233
paulson@1526
   234
wenzelm@3767
   235
wenzelm@3767
   236
(** add constant definitions **)
wenzelm@3767
   237
wenzelm@19708
   238
(* dependencies *)
wenzelm@19708
   239
wenzelm@19708
   240
fun dependencies thy unchecked is_def name lhs rhs =
wenzelm@19708
   241
  let
wenzelm@19708
   242
    val pp = Sign.pp thy;
wenzelm@19708
   243
    val consts = Sign.consts_of thy;
wenzelm@19727
   244
    fun prep const =
wenzelm@19727
   245
      let val Const (c, T) = Sign.no_vars pp (Const const)
wenzelm@19806
   246
      in (c, Consts.typargs consts (c, Compress.typ thy (Logic.varifyT T))) end;
wenzelm@19708
   247
wenzelm@19708
   248
    val lhs_vars = Term.add_tfreesT (#2 lhs) [];
wenzelm@19708
   249
    val rhs_extras = fold (#2 #> Term.fold_atyps (fn TFree v =>
wenzelm@19708
   250
      if member (op =) lhs_vars v then I else insert (op =) v | _ => I)) rhs [];
wenzelm@19708
   251
    val _ =
wenzelm@19708
   252
      if null rhs_extras then ()
wenzelm@19708
   253
      else error ("Specification depends on extra type variables: " ^
wenzelm@19708
   254
        commas_quote (map (Pretty.string_of_typ pp o TFree) rhs_extras) ^
wenzelm@19708
   255
        "\nThe error(s) above occurred in " ^ quote name);
haftmann@24199
   256
  in Defs.define pp unchecked is_def name (prep lhs) (map prep rhs) end;
wenzelm@19708
   257
wenzelm@19708
   258
fun add_deps a raw_lhs raw_rhs thy =
wenzelm@19708
   259
  let
wenzelm@19708
   260
    val lhs :: rhs = map (dest_Const o Sign.cert_term thy o Const) (raw_lhs :: raw_rhs);
wenzelm@19708
   261
    val name = if a = "" then (#1 lhs ^ " axiom") else a;
wenzelm@19708
   262
  in thy |> map_defs (dependencies thy false false name lhs rhs) end;
wenzelm@17706
   263
wenzelm@17706
   264
wenzelm@16944
   265
(* check_overloading *)
nipkow@9280
   266
wenzelm@16944
   267
fun check_overloading thy overloaded (c, T) =
wenzelm@16291
   268
  let
wenzelm@16944
   269
    val declT =
wenzelm@16944
   270
      (case Sign.const_constraint thy c of
wenzelm@16944
   271
        NONE => error ("Undeclared constant " ^ quote c)
wenzelm@16944
   272
      | SOME declT => declT);
wenzelm@19806
   273
    val T' = Logic.varifyT T;
wenzelm@16944
   274
wenzelm@16944
   275
    fun message txt =
wenzelm@16944
   276
      [Pretty.block [Pretty.str "Specification of constant ",
wenzelm@16944
   277
        Pretty.str c, Pretty.str " ::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ thy T)],
wenzelm@16944
   278
        Pretty.str txt] |> Pretty.chunks |> Pretty.string_of;
wenzelm@16291
   279
  in
wenzelm@16944
   280
    if Sign.typ_instance thy (declT, T') then ()
wenzelm@16944
   281
    else if Type.raw_instance (declT, T') then
wenzelm@16944
   282
      error (Library.setmp show_sorts true
wenzelm@16944
   283
        message "imposes additional sort constraints on the constant declaration")
wenzelm@16944
   284
    else if overloaded then ()
wenzelm@16944
   285
    else warning (message "is strictly less general than the declared type");
wenzelm@16944
   286
    (c, T)
nipkow@9280
   287
  end;
nipkow@9280
   288
wenzelm@3767
   289
wenzelm@16291
   290
(* check_def *)
wenzelm@16291
   291
wenzelm@19630
   292
fun check_def thy unchecked overloaded (bname, tm) defs =
wenzelm@16291
   293
  let
wenzelm@17706
   294
    val name = Sign.full_name thy bname;
wenzelm@19693
   295
    val (lhs_const, rhs) = Sign.cert_def (Sign.pp thy) tm;
wenzelm@16944
   296
    val rhs_consts = fold_aterms (fn Const const => insert (op =) const | _ => I) rhs [];
wenzelm@18943
   297
    val _ = check_overloading thy overloaded lhs_const;
wenzelm@19708
   298
  in defs |> dependencies thy unchecked true name lhs_const rhs_consts end
wenzelm@18678
   299
  handle ERROR msg => cat_error msg (Pretty.string_of (Pretty.block
wenzelm@16883
   300
   [Pretty.str ("The error(s) above occurred in definition " ^ quote bname ^ ":"),
wenzelm@19693
   301
    Pretty.fbrk, Pretty.quote (Sign.pretty_term thy tm)]));
wenzelm@3767
   302
wenzelm@3767
   303
wenzelm@16443
   304
(* add_defs(_i) *)
wenzelm@3767
   305
wenzelm@16291
   306
local
wenzelm@9320
   307
wenzelm@19630
   308
fun gen_add_defs prep_axm unchecked overloaded raw_axms thy =
wenzelm@16443
   309
  let val axms = map (prep_axm thy) raw_axms in
wenzelm@16443
   310
    thy
wenzelm@19630
   311
    |> map_defs (fold (check_def thy unchecked overloaded) axms)
wenzelm@9320
   312
    |> add_axioms_i axms
wenzelm@3767
   313
  end;
wenzelm@3767
   314
wenzelm@16291
   315
in
wenzelm@16291
   316
wenzelm@16291
   317
val add_defs_i = gen_add_defs cert_axm;
wenzelm@16291
   318
val add_defs = gen_add_defs read_axm;
wenzelm@16291
   319
wenzelm@16291
   320
end;
wenzelm@3767
   321
wenzelm@3767
   322
wenzelm@16443
   323
(* add_finals(_i) *)
skalberg@14223
   324
wenzelm@16291
   325
local
wenzelm@16291
   326
wenzelm@17706
   327
fun gen_add_finals prep_term overloaded args thy =
skalberg@14223
   328
  let
wenzelm@17706
   329
    fun const_of (Const const) = const
wenzelm@17706
   330
      | const_of (Free _) = error "Attempt to finalize variable (or undeclared constant)"
wenzelm@17706
   331
      | const_of _ = error "Attempt to finalize non-constant term";
wenzelm@19708
   332
    fun specify (c, T) = dependencies thy false false (c ^ " axiom") (c, T) [];
wenzelm@19708
   333
    val finalize = specify o check_overloading thy overloaded o const_of o prep_term thy;
wenzelm@17706
   334
  in thy |> map_defs (fold finalize args) end;
wenzelm@16291
   335
skalberg@14223
   336
in
wenzelm@16291
   337
wenzelm@17706
   338
val add_finals = gen_add_finals Sign.read_term;
wenzelm@17706
   339
val add_finals_i = gen_add_finals Sign.cert_term;
wenzelm@16291
   340
skalberg@14223
   341
end;
skalberg@14223
   342
skalberg@14223
   343
wenzelm@3878
   344
wenzelm@16443
   345
(** add oracle **)
wenzelm@3814
   346
wenzelm@16443
   347
fun add_oracle (bname, oracle) thy = thy |> map_oracles (fn oracles =>
haftmann@23086
   348
  NameSpace.extend_table (Sign.naming_of thy) [(bname, (oracle, stamp ()))] oracles
wenzelm@23655
   349
    handle Symtab.DUP dup => err_dup_ora dup);
wenzelm@3885
   350
paulson@1526
   351
end;
paulson@1526
   352
haftmann@24626
   353
functor TheoryInterpretatorFun(Key: THEORY_INTERPRETATOR_KEY) : THEORY_INTERPRETATOR =
haftmann@24626
   354
struct
haftmann@24626
   355
haftmann@24626
   356
open Key;
haftmann@24626
   357
haftmann@24626
   358
type interpretator = T list -> theory -> theory;
haftmann@24626
   359
haftmann@24626
   360
fun apply ips x = fold_rev (fn (_, f) => f x) ips;
haftmann@24626
   361
haftmann@24626
   362
structure InterpretatorData = TheoryDataFun (
haftmann@24626
   363
  type T = ((serial * interpretator) list * T list) * (theory -> theory);
haftmann@24626
   364
  val empty = (([], []), I);
haftmann@24626
   365
  val extend = I;
haftmann@24626
   366
  val copy = I;
haftmann@24626
   367
  fun merge pp (((interpretators1, done1), upd1), ((interpretators2, done2), upd2)) =
haftmann@24626
   368
    let
haftmann@24626
   369
      fun diff (interpretators1 : (serial * interpretator) list, done1)
haftmann@24626
   370
        (interpretators2, done2) = let
haftmann@24626
   371
          val interpretators = subtract (eq_fst (op =)) interpretators1 interpretators2;
haftmann@24626
   372
          val undone = subtract eq done2 done1;
haftmann@24626
   373
        in apply interpretators undone end;
haftmann@24626
   374
      val interpretators = AList.merge (op =) (K true) (interpretators1, interpretators2);
haftmann@24626
   375
      val done = Library.merge eq (done1, done2);
haftmann@24626
   376
      val upd_new = diff (interpretators2, done2) (interpretators1, done1)
haftmann@24626
   377
        #> diff (interpretators1, done1) (interpretators2, done2);
haftmann@24626
   378
      val upd = upd1 #> upd2 #> upd_new;
haftmann@24626
   379
    in ((interpretators, done), upd) end;
haftmann@24626
   380
);
haftmann@24626
   381
haftmann@24626
   382
fun consolidate thy =
haftmann@24626
   383
  let
haftmann@24626
   384
    val (_, upd) = InterpretatorData.get thy;
haftmann@24626
   385
  in
haftmann@24626
   386
    thy |> upd |> (InterpretatorData.map o apsnd) (K I)
haftmann@24626
   387
  end;
haftmann@24626
   388
haftmann@24626
   389
val init = Theory.add_consolidate consolidate;
haftmann@24626
   390
haftmann@24626
   391
fun add_those xs thy =
haftmann@24626
   392
  let
haftmann@24626
   393
    val ((interpretators, _), _) = InterpretatorData.get thy;
haftmann@24626
   394
  in
haftmann@24626
   395
    thy
haftmann@24626
   396
    |> apply interpretators xs
haftmann@24626
   397
    |> (InterpretatorData.map o apfst o apsnd) (append xs)
haftmann@24626
   398
  end;
haftmann@24626
   399
haftmann@24626
   400
val all_those = snd o fst o InterpretatorData.get;
haftmann@24626
   401
haftmann@24626
   402
fun add_interpretator interpretator thy =
haftmann@24626
   403
  let
haftmann@24626
   404
    val ((interpretators, xs), _) = InterpretatorData.get thy;
haftmann@24626
   405
  in
haftmann@24626
   406
    thy
haftmann@24626
   407
    |> interpretator (rev xs)
haftmann@24626
   408
    |> (InterpretatorData.map o apfst o apfst) (cons (serial (), interpretator))
haftmann@24626
   409
  end;
haftmann@24626
   410
haftmann@24626
   411
end;
haftmann@24626
   412
haftmann@24626
   413
structure Theory: THEORY = Theory;
wenzelm@3767
   414
structure BasicTheory: BASIC_THEORY = Theory;
wenzelm@3767
   415
open BasicTheory;