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