src/Pure/pure_thy.ML
author wenzelm
Mon Oct 01 16:37:22 2012 +0200 (2012-10-01)
changeset 49674 dbadb4d03cbc
parent 46483 10a9c31a22b4
child 49685 4341e4d86872
permissions -rw-r--r--
report sort assignment of visible type variables;
wenzelm@3987
     1
(*  Title:      Pure/pure_thy.ML
wenzelm@3987
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@3987
     3
wenzelm@39557
     4
Pure theory syntax and further logical content.
wenzelm@3987
     5
*)
wenzelm@3987
     6
wenzelm@3987
     7
signature PURE_THY =
wenzelm@3987
     8
sig
wenzelm@26959
     9
  val old_appl_syntax: theory -> bool
wenzelm@26959
    10
  val old_appl_syntax_setup: theory -> theory
wenzelm@3987
    11
end;
wenzelm@3987
    12
wenzelm@39557
    13
structure Pure_Thy: PURE_THY =
wenzelm@3987
    14
struct
wenzelm@3987
    15
wenzelm@33384
    16
val typ = Simple_Syntax.read_typ;
wenzelm@33384
    17
val prop = Simple_Syntax.read_prop;
wenzelm@35429
    18
wenzelm@42290
    19
val tycon = Lexicon.mark_type;
wenzelm@42290
    20
val const = Lexicon.mark_const;
wenzelm@24243
    21
wenzelm@26959
    22
wenzelm@26959
    23
(* application syntax variants *)
wenzelm@26959
    24
wenzelm@26959
    25
val appl_syntax =
wenzelm@26959
    26
 [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
wenzelm@26959
    27
  ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
wenzelm@26959
    28
wenzelm@26959
    29
val applC_syntax =
wenzelm@26959
    30
 [("",       typ "'a => cargs",                  Delimfix "_"),
wenzelm@26959
    31
  ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
wenzelm@26959
    32
  ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
wenzelm@26959
    33
  ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
wenzelm@26959
    34
wenzelm@37216
    35
structure Old_Appl_Syntax = Theory_Data
wenzelm@26959
    36
(
wenzelm@26959
    37
  type T = bool;
wenzelm@26959
    38
  val empty = false;
wenzelm@26959
    39
  val extend = I;
wenzelm@33522
    40
  fun merge (b1, b2) : T =
wenzelm@26959
    41
    if b1 = b2 then b1
wenzelm@26959
    42
    else error "Cannot merge theories with different application syntax";
wenzelm@26959
    43
);
wenzelm@26959
    44
wenzelm@37216
    45
val old_appl_syntax = Old_Appl_Syntax.get;
wenzelm@26959
    46
wenzelm@26959
    47
val old_appl_syntax_setup =
wenzelm@37216
    48
  Old_Appl_Syntax.put true #>
wenzelm@26959
    49
  Sign.del_modesyntax_i Syntax.mode_default applC_syntax #>
wenzelm@26959
    50
  Sign.add_syntax_i appl_syntax;
wenzelm@26959
    51
wenzelm@26959
    52
wenzelm@26959
    53
(* main content *)
wenzelm@26959
    54
wenzelm@26463
    55
val _ = Context.>> (Context.map_theory
haftmann@33365
    56
  (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
wenzelm@37216
    57
   Old_Appl_Syntax.put false #>
wenzelm@42375
    58
   Sign.add_types_global
wenzelm@30344
    59
   [(Binding.name "fun", 2, NoSyn),
wenzelm@30344
    60
    (Binding.name "prop", 0, NoSyn),
wenzelm@30344
    61
    (Binding.name "itself", 1, NoSyn),
wenzelm@30344
    62
    (Binding.name "dummy", 0, NoSyn)]
wenzelm@42375
    63
  #> Sign.add_nonterminals_global (map Binding.name Syntax.basic_nonterms)
wenzelm@42294
    64
  #> Sign.add_syntax_i (map (fn x => (x, typ "'a", NoSyn)) Syntax.token_markers)
wenzelm@26430
    65
  #> Sign.add_syntax_i
wenzelm@42294
    66
   [("",            typ "prop' => prop",               Delimfix "_"),
wenzelm@42294
    67
    ("",            typ "logic => any",                Delimfix "_"),
wenzelm@42294
    68
    ("",            typ "prop' => any",                Delimfix "_"),
wenzelm@42294
    69
    ("",            typ "logic => logic",              Delimfix "'(_')"),
wenzelm@42294
    70
    ("",            typ "prop' => prop'",              Delimfix "'(_')"),
wenzelm@42294
    71
    ("_constrain",  typ "logic => type => logic",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@42294
    72
    ("_constrain",  typ "prop' => type => prop'",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@49674
    73
    ("",            typ "tid_position => type",        Delimfix "_"),
wenzelm@49674
    74
    ("",            typ "tvar_position => type",       Delimfix "_"),
wenzelm@42263
    75
    ("",            typ "type_name => type",           Delimfix "_"),
wenzelm@42263
    76
    ("_type_name",  typ "id => type_name",             Delimfix "_"),
wenzelm@42263
    77
    ("_type_name",  typ "longid => type_name",         Delimfix "_"),
wenzelm@42297
    78
    ("_ofsort",     typ "tid => sort => type",         Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@42297
    79
    ("_ofsort",     typ "tvar => sort => type",        Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@42297
    80
    ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], 1000)),
wenzelm@42263
    81
    ("",            typ "class_name => sort",          Delimfix "_"),
wenzelm@42263
    82
    ("_class_name", typ "id => class_name",            Delimfix "_"),
wenzelm@42263
    83
    ("_class_name", typ "longid => class_name",        Delimfix "_"),
wenzelm@42263
    84
    ("_topsort",    typ "sort",                        Delimfix "{}"),
wenzelm@42263
    85
    ("_sort",       typ "classes => sort",             Delimfix "{_}"),
wenzelm@42263
    86
    ("",            typ "class_name => classes",       Delimfix "_"),
wenzelm@42263
    87
    ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
wenzelm@42297
    88
    ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [1000, 0], 1000)),
wenzelm@42263
    89
    ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
wenzelm@42263
    90
    ("",            typ "type => types",               Delimfix "_"),
wenzelm@42263
    91
    ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
wenzelm@42263
    92
    ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
wenzelm@42263
    93
    ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
wenzelm@42263
    94
    ("",            typ "type => type",                Delimfix "'(_')"),
wenzelm@42263
    95
    ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
wenzelm@42263
    96
    ("_type_prop",  typ "'a",                          NoSyn),
wenzelm@42263
    97
    ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@26436
    98
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@26436
    99
    ("",            typ "'a => args",                  Delimfix "_"),
wenzelm@26436
   100
    ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
wenzelm@42048
   101
    ("",            typ "id_position => idt",          Delimfix "_"),
wenzelm@26436
   102
    ("_idtdummy",   typ "idt",                         Delimfix "'_"),
wenzelm@42048
   103
    ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
wenzelm@26436
   104
    ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
wenzelm@26436
   105
    ("",            typ "idt => idt",                  Delimfix "'(_')"),
wenzelm@26436
   106
    ("",            typ "idt => idts",                 Delimfix "_"),
wenzelm@26436
   107
    ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
wenzelm@26436
   108
    ("",            typ "idt => pttrn",                Delimfix "_"),
wenzelm@26436
   109
    ("",            typ "pttrn => pttrns",             Delimfix "_"),
wenzelm@26436
   110
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
wenzelm@28856
   111
    ("",            typ "aprop => aprop",              Delimfix "'(_')"),
wenzelm@42048
   112
    ("",            typ "id_position => aprop",        Delimfix "_"),
wenzelm@42048
   113
    ("",            typ "longid_position => aprop",    Delimfix "_"),
wenzelm@26436
   114
    ("",            typ "var => aprop",                Delimfix "_"),
wenzelm@26436
   115
    ("_DDDOT",      typ "aprop",                       Delimfix "..."),
wenzelm@26436
   116
    ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
wenzelm@26436
   117
    ("_asm",        typ "prop => asms",                Delimfix "_"),
wenzelm@26436
   118
    ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
wenzelm@26436
   119
    ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@26436
   120
    ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
   121
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@26436
   122
    ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
wenzelm@42048
   123
    ("",            typ "id_position => logic",        Delimfix "_"),
wenzelm@42048
   124
    ("",            typ "longid_position => logic",    Delimfix "_"),
wenzelm@26436
   125
    ("",            typ "var => logic",                Delimfix "_"),
wenzelm@26436
   126
    ("_DDDOT",      typ "logic",                       Delimfix "..."),
wenzelm@42057
   127
    ("_strip_positions", typ "'a", NoSyn),
wenzelm@46236
   128
    ("_position",   typ "num_token => num_position",   Delimfix "_"),
wenzelm@46236
   129
    ("_position",   typ "float_token => float_position", Delimfix "_"),
wenzelm@46236
   130
    ("_position",   typ "xnum_token => xnum_position", Delimfix "_"),
wenzelm@46236
   131
    ("_constify",   typ "num_position => num_const",   Delimfix "_"),
wenzelm@46236
   132
    ("_constify",   typ "float_position => float_const", Delimfix "_"),
wenzelm@46236
   133
    ("_constify",   typ "xnum_position => xnum_const", Delimfix "_"),
wenzelm@26436
   134
    ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
wenzelm@26436
   135
    ("_indexdefault", typ "index",                     Delimfix ""),
wenzelm@26436
   136
    ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
wenzelm@26436
   137
    ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
wenzelm@35145
   138
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@42295
   139
    ("_constrainAbs", typ "'a",                        NoSyn),
wenzelm@49674
   140
    ("_position_sort", typ "tid => tid_position",      Delimfix "_"),
wenzelm@49674
   141
    ("_position_sort", typ "tvar => tvar_position",    Delimfix "_"),
wenzelm@42410
   142
    ("_position",   typ "id => id_position",           Delimfix "_"),
wenzelm@42410
   143
    ("_position",   typ "longid => longid_position",   Delimfix "_"),
wenzelm@46483
   144
    ("_position",   typ "str_token => str_position",   Delimfix "_"),
wenzelm@42048
   145
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@42296
   146
    ("_context_const", typ "id_position => logic",     Delimfix "CONST _"),
wenzelm@42296
   147
    ("_context_const", typ "id_position => aprop",     Delimfix "CONST _"),
wenzelm@42296
   148
    ("_context_const", typ "longid_position => logic", Delimfix "CONST _"),
wenzelm@42296
   149
    ("_context_const", typ "longid_position => aprop", Delimfix "CONST _"),
wenzelm@42296
   150
    ("_context_xconst", typ "id_position => logic",    Delimfix "XCONST _"),
wenzelm@42296
   151
    ("_context_xconst", typ "id_position => aprop",    Delimfix "XCONST _"),
wenzelm@42296
   152
    ("_context_xconst", typ "longid_position => logic", Delimfix "XCONST _"),
wenzelm@42296
   153
    ("_context_xconst", typ "longid_position => aprop", Delimfix "XCONST _"),
wenzelm@35255
   154
    (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
wenzelm@35255
   155
    (const Term.dummy_patternN, typ "aprop",           Delimfix "'_"),
wenzelm@28856
   156
    ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@35255
   157
    (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
wenzelm@35255
   158
    (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
wenzelm@26959
   159
  #> Sign.add_syntax_i applC_syntax
wenzelm@26430
   160
  #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
wenzelm@35429
   161
   [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
wenzelm@35429
   162
    ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
wenzelm@35429
   163
    ("_ofsort",           typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
wenzelm@35429
   164
    ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42293
   165
    ("_constrain",        typ "prop' => type => prop'", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42048
   166
    ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
wenzelm@35429
   167
    ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
wenzelm@35429
   168
    ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
wenzelm@35429
   169
    (const "==",          typ "'a => 'a => prop",       Infixr ("\\<equiv>", 2)),
wenzelm@35429
   170
    (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
wenzelm@35429
   171
    (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
wenzelm@35429
   172
    ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
wenzelm@35429
   173
    ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
wenzelm@35429
   174
    ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
wenzelm@26430
   175
  #> Sign.add_modesyntax_i ("", false)
wenzelm@35255
   176
   [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@26430
   177
  #> Sign.add_modesyntax_i ("HTML", false)
wenzelm@24243
   178
   [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
wenzelm@26430
   179
  #> Sign.add_consts_i
wenzelm@35130
   180
   [(Binding.name "==", typ "'a => 'a => prop", Infixr ("==", 2)),
wenzelm@30344
   181
    (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@30344
   182
    (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@30344
   183
    (Binding.name "prop", typ "prop => prop", NoSyn),
wenzelm@30344
   184
    (Binding.name "TYPE", typ "'a itself", NoSyn),
wenzelm@30344
   185
    (Binding.name Term.dummy_patternN, typ "'a", Delimfix "'_")]
wenzelm@42375
   186
  #> Theory.add_deps_global "==" ("==", typ "'a => 'a => prop") []
wenzelm@42375
   187
  #> Theory.add_deps_global "==>" ("==>", typ "prop => prop => prop") []
wenzelm@42375
   188
  #> Theory.add_deps_global "all" ("all", typ "('a => prop) => prop") []
wenzelm@42375
   189
  #> Theory.add_deps_global "TYPE" ("TYPE", typ "'a itself") []
wenzelm@42375
   190
  #> Theory.add_deps_global Term.dummy_patternN (Term.dummy_patternN, typ "'a") []
wenzelm@42284
   191
  #> Sign.add_trfuns Syntax_Trans.pure_trfuns
wenzelm@26430
   192
  #> Sign.local_path
wenzelm@26430
   193
  #> Sign.add_consts_i
wenzelm@30344
   194
   [(Binding.name "term", typ "'a => prop", NoSyn),
wenzelm@30344
   195
    (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn),
wenzelm@30344
   196
    (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)]
wenzelm@39557
   197
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
haftmann@29579
   198
   [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
haftmann@29579
   199
    (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
haftmann@29579
   200
    (Binding.name "sort_constraint_def",
wenzelm@28622
   201
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
wenzelm@28622
   202
      \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
haftmann@29579
   203
    (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@28622
   204
  #> Sign.hide_const false "Pure.term"
wenzelm@28622
   205
  #> Sign.hide_const false "Pure.sort_constraint"
wenzelm@26666
   206
  #> Sign.hide_const false "Pure.conjunction"
wenzelm@39557
   207
  #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
wenzelm@42375
   208
  #> fold (fn (a, prop) =>
wenzelm@42375
   209
      snd o Thm.add_axiom_global (Binding.name a, prop)) Proofterm.equality_axms));
wenzelm@3987
   210
wenzelm@3987
   211
end;