src/HOL/Tools/typedef_package.ML
author wenzelm
Thu, 11 Mar 1999 21:57:34 +0100
changeset 6357 12448b8f92fb
parent 6092 d9db67970c73
child 6383 45bb139e6ceb
permissions -rw-r--r--
named witnesses: PureThy.get_thmss; outer syntax for 'typedecl', 'typedef';
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Tools/typedef_package.ML
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
     4
6357
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
     5
Gordon/HOL-style type definitions.
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
     6
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
     7
TODO:
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
     8
  - typedefP: elim witness;
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
     9
*)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    10
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    11
signature TYPEDEF_PACKAGE =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    12
sig
5697
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    13
  val quiet_mode: bool ref
5104
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    14
  val add_typedecls: (bstring * string list * mixfix) list -> theory -> theory
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    15
  val prove_nonempty: cterm -> thm list -> tactic option -> thm
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    16
  val add_typedef: string -> bstring * string list * mixfix ->
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    17
    string -> string list -> thm list -> tactic option -> theory -> theory
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    18
  val add_typedef_i: string -> bstring * string list * mixfix ->
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    19
    term -> string list -> thm list -> tactic option -> theory -> theory
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
    20
  val add_typedef_i_no_def: string -> bstring * string list * mixfix ->
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
    21
    term -> string list -> thm list -> tactic option -> theory -> theory
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    22
end;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    23
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    24
structure TypedefPackage: TYPEDEF_PACKAGE =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    25
struct
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    26
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    27
5104
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    28
(** type declarations **)
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    29
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    30
fun add_typedecls decls thy =
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    31
  let
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    32
    val full = Sign.full_name (Theory.sign_of thy);
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    33
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    34
    fun arity_of (raw_name, args, mx) =
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    35
      (full (Syntax.type_name raw_name mx), replicate (length args) HOLogic.termS, HOLogic.termS);
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    36
  in
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    37
    thy
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    38
    |> PureThy.add_typedecls decls
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    39
    |> Theory.add_arities_i (map arity_of decls)
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    40
  end;
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    41
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    42
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    43
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    44
(** type definitions **)
230cca8452c7 added add_typedecls;
wenzelm
parents: 4970
diff changeset
    45
5697
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    46
(* messages *)
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    47
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    48
val quiet_mode = ref false;
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    49
fun message s = if ! quiet_mode then () else writeln s;
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    50
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
    51
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    52
(* prove non-emptyness of a set *)   (*exception ERROR*)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    53
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    54
val is_def = Logic.is_equals o #prop o rep_thm;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    55
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    56
fun prove_nonempty cset thms usr_tac =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    57
  let
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    58
    val {T = setT, t = set, maxidx, sign} = rep_cterm cset;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    59
    val T = HOLogic.dest_setT setT;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    60
    val goal = cterm_of sign
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    61
      (HOLogic.mk_Trueprop (HOLogic.mk_mem (Var (("x", maxidx + 1), T), set)));
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    62
    val tac =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    63
      TRY (rewrite_goals_tac (filter is_def thms)) THEN
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    64
      TRY (REPEAT_FIRST (resolve_tac (filter_out is_def thms))) THEN
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    65
      if_none usr_tac (TRY (ALLGOALS (CLASET' blast_tac)));
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    66
  in
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    67
    prove_goalw_cterm [] goal (K [tac])
6357
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
    68
  end handle ERROR => error ("Failed to prove nonemptiness of " ^ quote (string_of_cterm cset));
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    69
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    70
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    71
(* gen_add_typedef *)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    72
6357
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
    73
fun gen_add_typedef prep_term no_def name (t, vs, mx) raw_set thm_names thms usr_tac thy =
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    74
  let
4970
8b65444edbb0 Changed require to requires for MLWorks
paulson
parents: 4932
diff changeset
    75
    val _ = Theory.requires thy "Set" "typedefs";
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    76
    val sign = sign_of thy;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    77
    val full_name = Sign.full_name sign;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    78
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    79
    (*rhs*)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    80
    val cset = prep_term sign raw_set;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    81
    val {T = setT, t = set, ...} = rep_cterm cset;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    82
    val rhs_tfrees = term_tfrees set;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    83
    val oldT = HOLogic.dest_setT setT handle TYPE _ =>
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    84
      error ("Not a set type: " ^ quote (Sign.string_of_typ sign setT));
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    85
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    86
    (*lhs*)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    87
    val lhs_tfrees =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    88
      map (fn v => (v, if_none (assoc (rhs_tfrees, v)) HOLogic.termS)) vs;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    89
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    90
    val tname = Syntax.type_name t mx;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    91
    val newT = Type (full_name tname, map TFree lhs_tfrees);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    92
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    93
    val Rep_name = "Rep_" ^ name;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    94
    val Abs_name = "Abs_" ^ name;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    95
    val setC = Const (full_name name, setT);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    96
    val RepC = Const (full_name Rep_name, newT --> oldT);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    97
    val AbsC = Const (full_name Abs_name, oldT --> newT);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    98
    val x_new = Free ("x", newT);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
    99
    val y_old = Free ("y", oldT);
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   100
    val set' = if no_def then set else setC;
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   101
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   102
    (*axioms*)
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   103
    val rep_type = HOLogic.mk_Trueprop (HOLogic.mk_mem (RepC $ x_new, set'));
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   104
    val rep_type_inv = HOLogic.mk_Trueprop (HOLogic.mk_eq (AbsC $ (RepC $ x_new), x_new));
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   105
    val abs_type_inv = Logic.mk_implies (HOLogic.mk_Trueprop (HOLogic.mk_mem (y_old, set')),
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   106
      HOLogic.mk_Trueprop (HOLogic.mk_eq (RepC $ (AbsC $ y_old), y_old)));
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   107
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   108
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   109
    (* errors *)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   110
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   111
    fun show_names pairs = commas_quote (map fst pairs);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   112
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   113
    val illegal_vars =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   114
      if null (term_vars set) andalso null (term_tvars set) then []
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   115
      else ["Illegal schematic variable(s) on rhs"];
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   116
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   117
    val dup_lhs_tfrees =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   118
      (case duplicates lhs_tfrees of [] => []
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   119
      | dups => ["Duplicate type variables on lhs: " ^ show_names dups]);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   120
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   121
    val extra_rhs_tfrees =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   122
      (case gen_rems (op =) (rhs_tfrees, lhs_tfrees) of [] => []
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   123
      | extras => ["Extra type variables on rhs: " ^ show_names extras]);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   124
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   125
    val illegal_frees =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   126
      (case term_frees set of [] => []
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   127
      | xs => ["Illegal variables on rhs: " ^ show_names (map dest_Free xs)]);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   128
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   129
    val errs = illegal_vars @ dup_lhs_tfrees @ extra_rhs_tfrees @ illegal_frees;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   130
  in
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   131
    if null errs then ()
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   132
    else error (cat_lines errs);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   133
5697
e816c4f1a396 quiet_mode, message;
wenzelm
parents: 5180
diff changeset
   134
    message ("Proving nonemptiness of " ^ quote name ^ " ...");
6357
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   135
    prove_nonempty cset (PureThy.get_thmss thy thm_names @ thms) usr_tac;
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   136
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   137
    thy
4932
c90411dde8e8 PureThy.add_typedecls;
wenzelm
parents: 4866
diff changeset
   138
    |> PureThy.add_typedecls [(t, vs, mx)]
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   139
    |> Theory.add_arities_i
4932
c90411dde8e8 PureThy.add_typedecls;
wenzelm
parents: 4866
diff changeset
   140
     [(full_name tname, replicate (length vs) HOLogic.termS, HOLogic.termS)]
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   141
    |> Theory.add_consts_i
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   142
     ((if no_def then [] else [(name, setT, NoSyn)]) @
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   143
      [(Rep_name, newT --> oldT, NoSyn),
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   144
       (Abs_name, oldT --> newT, NoSyn)])
6092
d9db67970c73 eliminated tthm type and Attribute structure;
wenzelm
parents: 5697
diff changeset
   145
    |> (if no_def then I else (PureThy.add_defs_i o map Thm.no_attributes)
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   146
     [(name ^ "_def", Logic.mk_equals (setC, set))])
6092
d9db67970c73 eliminated tthm type and Attribute structure;
wenzelm
parents: 5697
diff changeset
   147
    |> (PureThy.add_axioms_i o map Thm.no_attributes)
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   148
     [(Rep_name, rep_type),
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   149
      (Rep_name ^ "_inverse", rep_type_inv),
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   150
      (Abs_name ^ "_inverse", abs_type_inv)]
6357
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   151
  end handle ERROR => error ("The error(s) above occurred in typedef " ^ quote name);
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   152
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   153
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   154
(* external interfaces *)
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   155
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   156
fun read_term sg str =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   157
  read_cterm sg (str, HOLogic.termTVar);
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   158
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   159
fun cert_term sg tm =
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   160
  cterm_of sg tm handle TERM (msg, _) => error msg;
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   161
5180
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   162
val add_typedef = gen_add_typedef read_term false;
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   163
val add_typedef_i = gen_add_typedef cert_term false;
d82a70766af0 Added new function add_typedef_i_no_def which doesn't add
berghofe
parents: 5104
diff changeset
   164
val add_typedef_i_no_def = gen_add_typedef cert_term true;
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   165
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   166
6357
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   167
(* outer syntax *)
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   168
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   169
open OuterParse;
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   170
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   171
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   172
val typedeclP =
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   173
  OuterSyntax.parser false "typedecl" "HOL type declaration"
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   174
    ((type_args -- name -- opt_mixfix) >> (fn ((vs, t), mx) =>
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   175
      Toplevel.theory (add_typedecls [(t, vs, mx)])));
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   176
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   177
val opt_witness =
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   178
  Scan.optional ($$$ "(" |-- !!! (list1 xname --| $$$ ")")) [];
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   179
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   180
val typedef_decl =
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   181
  Scan.option ($$$ "(" |-- name --| $$$ ")") --
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   182
    (type_args -- name) -- opt_infix -- ($$$ "=" |-- term -- opt_witness);
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   183
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   184
val typedefP =
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   185
  OuterSyntax.parser false "typedef" "HOL type definition"
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   186
    (typedef_decl >> (fn (((opt_name, (vs, t)), mx), (A, witn)) =>
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   187
      Toplevel.theory (add_typedef (if_none opt_name t) (t, vs, mx) A witn [] None)));
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   188
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   189
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   190
val _ = OuterSyntax.add_parsers [typedeclP, typedefP];
12448b8f92fb named witnesses: PureThy.get_thmss;
wenzelm
parents: 6092
diff changeset
   191
4866
72a46bd00c8d renamed from typedef.ML;
wenzelm
parents:
diff changeset
   192
end;