src/Pure/Isar/theory_target.ML
author wenzelm
Sat Jun 02 18:05:34 2007 +0200 (2007-06-02)
changeset 23205 b12f1c03cc9a
parent 23087 ad7244663431
child 24218 fbf1646b267c
permissions -rw-r--r--
added target/local_abbrev (from proof_context.ML);
target_abbrev: demand equal head const (tool compliance);
wenzelm@20894
     1
(*  Title:      Pure/Isar/theory_target.ML
wenzelm@20894
     2
    ID:         $Id$
wenzelm@20894
     3
    Author:     Makarius
wenzelm@20894
     4
wenzelm@21594
     5
Common theory/locale targets.
wenzelm@20894
     6
*)
wenzelm@20894
     7
wenzelm@20894
     8
signature THEORY_TARGET =
wenzelm@20894
     9
sig
wenzelm@21006
    10
  val peek: local_theory -> string option
haftmann@22353
    11
  val begin: bstring -> Proof.context -> local_theory
wenzelm@20894
    12
  val init: xstring option -> theory -> local_theory
wenzelm@20894
    13
  val init_i: string option -> theory -> local_theory
wenzelm@20894
    14
end;
wenzelm@20894
    15
wenzelm@20894
    16
structure TheoryTarget: THEORY_TARGET =
wenzelm@20894
    17
struct
wenzelm@20894
    18
wenzelm@20894
    19
(** locale targets **)
wenzelm@20894
    20
wenzelm@21006
    21
(* context data *)
wenzelm@21006
    22
wenzelm@21006
    23
structure Data = ProofDataFun
wenzelm@21006
    24
(
wenzelm@21006
    25
  type T = string option;
wenzelm@21006
    26
  fun init _ = NONE;
wenzelm@21006
    27
);
wenzelm@21006
    28
wenzelm@21006
    29
val peek = Data.get;
wenzelm@21006
    30
wenzelm@21006
    31
wenzelm@20894
    32
(* pretty *)
wenzelm@20894
    33
wenzelm@20894
    34
fun pretty loc ctxt =
wenzelm@20894
    35
  let
wenzelm@20894
    36
    val thy = ProofContext.theory_of ctxt;
wenzelm@20894
    37
    val fixes = map (fn (x, T) => (x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt));
wenzelm@21585
    38
    val assumes = map (fn A => (("", []), [(A, [])])) (map Thm.term_of (Assumption.assms_of ctxt));
wenzelm@20894
    39
    val elems =
wenzelm@20894
    40
      (if null fixes then [] else [Element.Fixes fixes]) @
wenzelm@20894
    41
      (if null assumes then [] else [Element.Assumes assumes]);
wenzelm@20894
    42
  in
wenzelm@20984
    43
    if loc = "" then
wenzelm@20984
    44
      [Pretty.block
wenzelm@20984
    45
        [Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy),
wenzelm@20984
    46
          Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]]
wenzelm@20984
    47
    else if null elems then [Pretty.str ("locale " ^ Locale.extern thy loc)]
wenzelm@20984
    48
    else
wenzelm@20984
    49
      [Pretty.big_list ("locale " ^ Locale.extern thy loc ^ " =")
wenzelm@20984
    50
        (map (Pretty.chunks o Element.pretty_ctxt ctxt) elems)]
wenzelm@20894
    51
  end;
wenzelm@20894
    52
wenzelm@20894
    53
wenzelm@21804
    54
(* consts *)
wenzelm@21804
    55
wenzelm@23205
    56
fun target_abbrev prmode ((c, mx), rhs) phi =
wenzelm@23205
    57
  let
wenzelm@23205
    58
    val c' = Morphism.name phi c;
wenzelm@23205
    59
    val rhs' = Morphism.term phi rhs;
wenzelm@23205
    60
    val arg' = (c', rhs');
wenzelm@23205
    61
    val eq_heads =
wenzelm@23205
    62
      (case pairself Term.head_of (rhs, rhs') of
wenzelm@23205
    63
        (Const (a, _), Const (a', _)) => a = a'
wenzelm@23205
    64
      | _ => false);
wenzelm@23205
    65
  in
wenzelm@23205
    66
    eq_heads ? (Context.mapping_result
wenzelm@23205
    67
      (Sign.add_abbrev Syntax.internalM arg') (ProofContext.add_abbrev Syntax.internalM arg')
wenzelm@23205
    68
    #-> (fn (lhs, _) =>
wenzelm@23205
    69
      Term.equiv_types (rhs, rhs') ?
wenzelm@23205
    70
        Morphism.form (ProofContext.target_notation prmode [(lhs, mx)])))
wenzelm@23205
    71
  end;
wenzelm@23205
    72
wenzelm@21825
    73
fun internal_abbrev prmode ((c, mx), t) =
wenzelm@22380
    74
  (* FIXME really permissive *)
wenzelm@23205
    75
  LocalTheory.term_syntax (perhaps o try o target_abbrev prmode ((c, mx), t))
haftmann@23087
    76
  #> ProofContext.add_abbrev Syntax.internalM (c, t) #> snd;
wenzelm@21804
    77
haftmann@22353
    78
fun consts is_loc some_class depends decls lthy =
wenzelm@21804
    79
  let
wenzelm@21804
    80
    val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy)));
wenzelm@21747
    81
wenzelm@21804
    82
    fun const ((c, T), mx) thy =
wenzelm@21804
    83
      let
wenzelm@21804
    84
        val U = map #2 xs ---> T;
wenzelm@21804
    85
        val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs);
haftmann@22353
    86
        val (mx1, mx2) = ClassPackage.fork_mixfix is_loc some_class mx;
wenzelm@21804
    87
        val thy' = Sign.add_consts_authentic [(c, U, mx1)] thy;
wenzelm@21804
    88
      in (((c, mx2), t), thy') end;
wenzelm@21804
    89
haftmann@23087
    90
    fun const_class (SOME class) ((c, _), mx) (_, t) =
haftmann@23087
    91
          ClassPackage.add_const_in_class class ((c, t), mx)
haftmann@23087
    92
      | const_class NONE _ _ = I;
haftmann@23087
    93
haftmann@23087
    94
    val (abbrs, lthy') = lthy
haftmann@23087
    95
      |> LocalTheory.theory_result (fold_map const decls)
wenzelm@21804
    96
    val defs = map (apsnd (pair ("", []))) abbrs;
wenzelm@21804
    97
  in
wenzelm@21804
    98
    lthy'
wenzelm@21825
    99
    |> is_loc ? fold (internal_abbrev Syntax.default_mode) abbrs
haftmann@23087
   100
    |> LocalTheory.raw_theory (fold2 (const_class some_class) decls abbrs)
haftmann@23087
   101
    |> LocalDefs.add_defs defs
haftmann@23087
   102
    |>> map (apsnd snd)
wenzelm@21804
   103
  end;
wenzelm@21804
   104
wenzelm@21804
   105
wenzelm@21804
   106
(* abbrev *)
wenzelm@21747
   107
wenzelm@21747
   108
fun occ_params ctxt ts =
wenzelm@21747
   109
  #1 (ProofContext.inferred_fixes ctxt)
wenzelm@21747
   110
  |> filter (member (op =) (fold (Variable.add_fixed ctxt) ts []));
wenzelm@21747
   111
wenzelm@23205
   112
fun local_abbrev (x, rhs) =
wenzelm@23205
   113
  Variable.add_fixes [x] #-> (fn [x'] =>
wenzelm@23205
   114
    let
wenzelm@23205
   115
      val T = Term.fastype_of rhs;
wenzelm@23205
   116
      val lhs = Free (x', T);
wenzelm@23205
   117
    in
wenzelm@23205
   118
      Variable.declare_term lhs #>
wenzelm@23205
   119
      Variable.declare_term rhs #>
wenzelm@23205
   120
      Assumption.add_assms (K (K (I, Envir.expand_term_frees [((x', T), rhs)]))) [] #> snd #>
wenzelm@23205
   121
      pair (lhs, rhs)
wenzelm@23205
   122
    end);
wenzelm@23205
   123
haftmann@23087
   124
fun abbrev is_loc some_class prmode ((raw_c, mx), raw_t) lthy =
wenzelm@21747
   125
  let
wenzelm@21747
   126
    val thy_ctxt = ProofContext.init (ProofContext.theory_of lthy);
wenzelm@21747
   127
    val target = LocalTheory.target_of lthy;
wenzelm@21747
   128
    val target_morphism = LocalTheory.target_morphism lthy;
wenzelm@21747
   129
wenzelm@21747
   130
    val c = Morphism.name target_morphism raw_c;
wenzelm@21747
   131
    val t = Morphism.term target_morphism raw_t;
wenzelm@21747
   132
    val xs = map Free (occ_params target [t]);
wenzelm@21747
   133
    val u = fold_rev Term.lambda xs t;
wenzelm@21804
   134
    val U = Term.fastype_of u;
wenzelm@21747
   135
    val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u;
wenzelm@21747
   136
wenzelm@21804
   137
    val ((lhs as Const (full_c, _), rhs), lthy1) = lthy
wenzelm@21747
   138
      |> LocalTheory.theory_result (Sign.add_abbrev (#1 prmode) (c, u'));
haftmann@22353
   139
    val (mx1, mx2) = ClassPackage.fork_mixfix is_loc some_class mx;
wenzelm@21747
   140
  in
wenzelm@21747
   141
    lthy1
wenzelm@21804
   142
    |> LocalTheory.theory (Sign.add_notation prmode [(lhs, mx1)])
wenzelm@21825
   143
    |> is_loc ? internal_abbrev prmode ((c, mx2), Term.list_comb (Const (full_c, U), xs))
wenzelm@23205
   144
    |> local_abbrev (c, rhs)
wenzelm@21747
   145
  end;
wenzelm@21747
   146
wenzelm@21747
   147
wenzelm@20894
   148
(* defs *)
wenzelm@20894
   149
wenzelm@21845
   150
local
wenzelm@21570
   151
wenzelm@21594
   152
fun expand_term ctxt t =
wenzelm@21570
   153
  let
wenzelm@21570
   154
    val thy = ProofContext.theory_of ctxt;
wenzelm@21570
   155
    val thy_ctxt = ProofContext.init thy;
wenzelm@21570
   156
    val ct = Thm.cterm_of thy t;
wenzelm@21594
   157
    val (defs, ct') = LocalDefs.export ctxt thy_ctxt (Drule.mk_term ct) ||> Drule.dest_term;
wenzelm@21708
   158
  in (Thm.term_of ct', MetaSimplifier.rewrite true defs ct) end;
wenzelm@21570
   159
wenzelm@20894
   160
fun add_def (name, prop) =
wenzelm@20894
   161
  Theory.add_defs_i false false [(name, prop)] #>
wenzelm@20894
   162
  (fn thy => (Drule.unvarify (Thm.get_axiom_i thy (Sign.full_name thy name)), thy));
wenzelm@20894
   163
wenzelm@20894
   164
in
wenzelm@20894
   165
haftmann@23087
   166
fun defs loc kind args lthy0 =
wenzelm@20894
   167
  let
wenzelm@21533
   168
    fun def ((c, mx), ((name, atts), rhs)) lthy1 =
wenzelm@20894
   169
      let
wenzelm@21594
   170
        val (rhs', rhs_conv) = expand_term lthy0 rhs;
wenzelm@21570
   171
        val xs = Variable.add_fixed (LocalTheory.target_of lthy0) rhs' [];
haftmann@23087
   172
        val T = Term.fastype_of rhs;
wenzelm@20894
   173
wenzelm@21570
   174
        val ([(lhs, lhs_def)], lthy2) = lthy1
haftmann@23087
   175
          |> LocalTheory.consts (member (op =) xs) [((c, T), mx)];
wenzelm@21570
   176
        val lhs' = #2 (Logic.dest_equals (Thm.prop_of lhs_def));
wenzelm@21533
   177
wenzelm@21570
   178
        val name' = Thm.def_name_optional c name;
wenzelm@21570
   179
        val (def, lthy3) = lthy2
wenzelm@20894
   180
          |> LocalTheory.theory_result (add_def (name', Logic.mk_equals (lhs', rhs')));
wenzelm@21845
   181
        val eq = LocalDefs.trans_terms lthy3
wenzelm@21845
   182
          [(*c == loc.c xs*) lhs_def,
wenzelm@21845
   183
           (*lhs' == rhs'*)  def,
wenzelm@21845
   184
           (*rhs' == rhs*)   Thm.symmetric rhs_conv];
haftmann@23087
   185
      in ((lhs, ((name', atts), [([eq], [])])), lthy3) end;
wenzelm@20894
   186
wenzelm@21570
   187
    val ((lhss, facts), lthy') = lthy0 |> fold_map def args |>> split_list;
wenzelm@21433
   188
    val (res, lthy'') = lthy' |> LocalTheory.notes kind facts;
haftmann@22424
   189
wenzelm@20894
   190
  in (lhss ~~ map (apsnd the_single) res, lthy'') end;
wenzelm@20894
   191
wenzelm@20894
   192
end;
wenzelm@20894
   193
wenzelm@20894
   194
wenzelm@21611
   195
(* axioms *)
wenzelm@21611
   196
wenzelm@21611
   197
local
wenzelm@21611
   198
wenzelm@21611
   199
fun add_axiom hyps (name, prop) thy =
wenzelm@21611
   200
  let
wenzelm@21611
   201
    val name' = if name = "" then "axiom_" ^ serial_string () else name;
wenzelm@21611
   202
    val prop' = Logic.list_implies (hyps, prop);
wenzelm@21611
   203
    val thy' = thy |> Theory.add_axioms_i [(name', prop')];
wenzelm@21611
   204
    val axm = Drule.unvarify (Thm.get_axiom_i thy' (Sign.full_name thy' name'));
wenzelm@21611
   205
    val prems = map (Thm.assume o Thm.cterm_of thy') hyps;
wenzelm@21611
   206
  in (Drule.implies_elim_list axm prems, thy') end;
wenzelm@21611
   207
wenzelm@21611
   208
in
wenzelm@21611
   209
wenzelm@21611
   210
fun axioms kind specs lthy =
wenzelm@21611
   211
  let
wenzelm@21611
   212
    val hyps = map Thm.term_of (Assumption.assms_of lthy);
wenzelm@21611
   213
    fun axiom ((name, atts), props) thy = thy
wenzelm@21611
   214
      |> fold_map (add_axiom hyps) (PureThy.name_multi name props)
wenzelm@21611
   215
      |-> (fn ths => pair ((name, atts), [(ths, [])]));
wenzelm@21611
   216
  in
wenzelm@21611
   217
    lthy
wenzelm@21611
   218
    |> fold (fold Variable.declare_term o snd) specs
wenzelm@21611
   219
    |> LocalTheory.theory_result (fold_map axiom specs)
wenzelm@21611
   220
    |-> LocalTheory.notes kind
wenzelm@21611
   221
  end;
wenzelm@21611
   222
wenzelm@21611
   223
end;
wenzelm@21611
   224
wenzelm@21611
   225
wenzelm@20894
   226
(* notes *)
wenzelm@20894
   227
wenzelm@21611
   228
fun import_export_proof ctxt (name, raw_th) =
wenzelm@21594
   229
  let
wenzelm@21611
   230
    val thy = ProofContext.theory_of ctxt;
wenzelm@21611
   231
    val thy_ctxt = ProofContext.init thy;
wenzelm@21611
   232
    val certT = Thm.ctyp_of thy;
wenzelm@21611
   233
    val cert = Thm.cterm_of thy;
wenzelm@21594
   234
wenzelm@21611
   235
    (*export assumes/defines*)
wenzelm@21611
   236
    val th = Goal.norm_result raw_th;
wenzelm@21611
   237
    val (defs, th') = LocalDefs.export ctxt thy_ctxt th;
wenzelm@21708
   238
    val concl_conv = MetaSimplifier.rewrite true defs (Thm.cprop_of th);
wenzelm@21708
   239
    val assms = map (MetaSimplifier.rewrite_rule defs o Thm.assume) (Assumption.assms_of ctxt);
wenzelm@21611
   240
    val nprems = Thm.nprems_of th' - Thm.nprems_of th;
wenzelm@21611
   241
wenzelm@21611
   242
    (*export fixes*)
wenzelm@22692
   243
    val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
wenzelm@22692
   244
    val frees = map Free (Thm.fold_terms Term.add_frees th' []);
wenzelm@21611
   245
    val (th'' :: vs) = (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees))
wenzelm@21611
   246
      |> Variable.export ctxt thy_ctxt
wenzelm@21611
   247
      |> Drule.zero_var_indexes_list;
wenzelm@21611
   248
wenzelm@21611
   249
    (*thm definition*)
wenzelm@21644
   250
    val result = th''
wenzelm@21644
   251
      |> PureThy.name_thm true true ""
wenzelm@21644
   252
      |> Goal.close_result
wenzelm@21644
   253
      |> PureThy.name_thm true true name;
wenzelm@21611
   254
wenzelm@21611
   255
    (*import fixes*)
wenzelm@21611
   256
    val (tvars, vars) =
wenzelm@21611
   257
      chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs)
wenzelm@21611
   258
      |>> map Logic.dest_type;
wenzelm@21611
   259
wenzelm@21611
   260
    val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
wenzelm@21611
   261
    val inst = filter (is_Var o fst) (vars ~~ frees);
wenzelm@21611
   262
    val cinstT = map (pairself certT o apfst TVar) instT;
wenzelm@21611
   263
    val cinst = map (pairself (cert o Term.map_types (TermSubst.instantiateT instT))) inst;
wenzelm@21611
   264
    val result' = Thm.instantiate (cinstT, cinst) result;
wenzelm@21611
   265
wenzelm@21611
   266
    (*import assumes/defines*)
wenzelm@21594
   267
    val assm_tac = FIRST' (map (fn assm => Tactic.compose_tac (false, assm, 0)) assms);
wenzelm@21611
   268
    val result'' =
wenzelm@21611
   269
      (case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of
wenzelm@21611
   270
        NONE => raise THM ("Failed to re-import result", 0, [result'])
wenzelm@21845
   271
      | SOME res => LocalDefs.trans_props ctxt [res, Thm.symmetric concl_conv])
wenzelm@21644
   272
      |> Goal.norm_result
wenzelm@21644
   273
      |> PureThy.name_thm false false name;
wenzelm@21611
   274
wenzelm@21611
   275
  in (result'', result) end;
wenzelm@21611
   276
wenzelm@21594
   277
fun notes loc kind facts lthy =
wenzelm@21585
   278
  let
wenzelm@21594
   279
    val is_loc = loc <> "";
wenzelm@21594
   280
    val thy = ProofContext.theory_of lthy;
wenzelm@21615
   281
    val full = LocalTheory.full_name lthy;
wenzelm@21585
   282
wenzelm@21594
   283
    val facts' = facts
wenzelm@21615
   284
      |> map (fn (a, bs) => (a, PureThy.burrow_fact (PureThy.name_multi (full (fst a))) bs))
wenzelm@21615
   285
      |> PureThy.map_facts (import_export_proof lthy);
wenzelm@21611
   286
    val local_facts = PureThy.map_facts #1 facts'
wenzelm@21611
   287
      |> Attrib.map_facts (Attrib.attribute_i thy);
wenzelm@21611
   288
    val target_facts = PureThy.map_facts #1 facts'
wenzelm@21611
   289
      |> is_loc ? Element.facts_map (Element.morph_ctxt (LocalTheory.target_morphism lthy));
wenzelm@21611
   290
    val global_facts = PureThy.map_facts #2 facts'
wenzelm@21594
   291
      |> Attrib.map_facts (if is_loc then K I else Attrib.attribute_i thy);
wenzelm@21594
   292
  in
wenzelm@21611
   293
    lthy |> LocalTheory.theory
wenzelm@21611
   294
      (Sign.qualified_names
wenzelm@21611
   295
        #> PureThy.note_thmss_i kind global_facts #> snd
wenzelm@21611
   296
        #> Sign.restore_naming thy)
wenzelm@21585
   297
wenzelm@21611
   298
    |> is_loc ? LocalTheory.target (Locale.add_thmss loc kind target_facts)
wenzelm@21594
   299
wenzelm@21433
   300
    |> ProofContext.set_stmt true
wenzelm@20894
   301
    |> ProofContext.qualified_names
wenzelm@21611
   302
    |> ProofContext.note_thmss_i kind local_facts
wenzelm@20894
   303
    ||> ProofContext.restore_naming lthy
wenzelm@21433
   304
    ||> ProofContext.restore_stmt lthy
wenzelm@20894
   305
  end;
wenzelm@20894
   306
wenzelm@20894
   307
wenzelm@21533
   308
(* target declarations *)
wenzelm@20894
   309
wenzelm@22673
   310
fun target_decl add loc d lthy =
wenzelm@22673
   311
  let
wenzelm@22673
   312
    val d' = Morphism.transform (LocalTheory.target_morphism lthy) d;
wenzelm@22673
   313
    val d0 = Morphism.form d';
wenzelm@22673
   314
  in
wenzelm@22673
   315
    if loc = "" then
wenzelm@22673
   316
      lthy
wenzelm@22673
   317
      |> LocalTheory.theory (Context.theory_map d0)
wenzelm@22673
   318
      |> LocalTheory.target (Context.proof_map d0)
wenzelm@22673
   319
    else
wenzelm@22673
   320
      lthy
wenzelm@22673
   321
      |> LocalTheory.target (add loc d')
wenzelm@22673
   322
  end;
wenzelm@20894
   323
wenzelm@21611
   324
val type_syntax = target_decl Locale.add_type_syntax;
wenzelm@21611
   325
val term_syntax = target_decl Locale.add_term_syntax;
wenzelm@21611
   326
val declaration = target_decl Locale.add_declaration;
wenzelm@20894
   327
wenzelm@21533
   328
fun target_morphism loc lthy =
wenzelm@21594
   329
  ProofContext.export_morphism lthy (LocalTheory.target_of lthy) $>
wenzelm@21613
   330
  Morphism.thm_morphism Goal.norm_result;
wenzelm@21533
   331
wenzelm@22203
   332
fun target_naming loc lthy =
wenzelm@21668
   333
  (if loc = "" then Sign.naming_of (ProofContext.theory_of lthy)
wenzelm@21668
   334
   else ProofContext.naming_of (LocalTheory.target_of lthy))
wenzelm@22203
   335
  |> NameSpace.qualified_names;
wenzelm@21533
   336
wenzelm@20894
   337
wenzelm@20894
   338
(* init and exit *)
wenzelm@20894
   339
haftmann@22353
   340
fun begin loc ctxt =
haftmann@22353
   341
  let
haftmann@22353
   342
    val thy = ProofContext.theory_of ctxt;
haftmann@22353
   343
    val is_loc = loc <> "";
haftmann@22353
   344
    val some_class = ClassPackage.class_of_locale thy loc;
haftmann@22353
   345
  in
haftmann@22353
   346
    ctxt
haftmann@22353
   347
    |> Data.put (if is_loc then SOME loc else NONE)
haftmann@22353
   348
    |> LocalTheory.init (NameSpace.base loc)
wenzelm@21747
   349
     {pretty = pretty loc,
haftmann@22353
   350
      consts = consts is_loc some_class,
wenzelm@21747
   351
      axioms = axioms,
haftmann@22353
   352
      abbrev = abbrev is_loc some_class,
haftmann@23087
   353
      defs = defs loc,
wenzelm@21747
   354
      notes = notes loc,
wenzelm@21747
   355
      type_syntax = type_syntax loc,
wenzelm@21747
   356
      term_syntax = term_syntax loc,
wenzelm@21747
   357
      declaration = declaration loc,
wenzelm@21747
   358
      target_morphism = target_morphism loc,
wenzelm@22203
   359
      target_naming = target_naming loc,
wenzelm@21804
   360
      reinit = fn _ =>
haftmann@22353
   361
        begin loc o (if is_loc then Locale.init loc else ProofContext.init),
wenzelm@21747
   362
      exit = LocalTheory.target_of}
wenzelm@21747
   363
  end;
wenzelm@20894
   364
haftmann@22353
   365
fun init_i NONE thy = begin "" (ProofContext.init thy)
haftmann@22353
   366
  | init_i (SOME loc) thy = begin loc (Locale.init loc thy);
wenzelm@20894
   367
wenzelm@21276
   368
fun init (SOME "-") thy = init_i NONE thy
wenzelm@21276
   369
  | init loc thy = init_i (Option.map (Locale.intern thy) loc) thy;
wenzelm@20894
   370
wenzelm@20894
   371
end;