author | blanchet |
Mon, 15 Sep 2014 10:49:07 +0200 | |
changeset 58335 | a5a3b576fcfb |
parent 58239 | 1c5bc387bd4c |
child 58662 | 5963cdbad926 |
permissions | -rw-r--r-- |
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
30345
diff
changeset
|
1 |
(* Title: HOL/Tools/typedef.ML |
16458 | 2 |
Author: Markus Wenzel and Stefan Berghofer, TU Muenchen |
4866 | 3 |
|
21352 | 4 |
Gordon/HOL-style type definitions: create a new syntactic type |
35741 | 5 |
represented by a non-empty set. |
4866 | 6 |
*) |
7 |
||
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
30345
diff
changeset
|
8 |
signature TYPEDEF = |
4866 | 9 |
sig |
19705 | 10 |
type info = |
36107 | 11 |
{rep_type: typ, abs_type: typ, Rep_name: string, Abs_name: string, axiom_name: string} * |
49833 | 12 |
{inhabited: thm, type_definition: thm, Rep: thm, Rep_inverse: thm, Abs_inverse: thm, |
13 |
Rep_inject: thm, Abs_inject: thm, Rep_cases: thm, Abs_cases: thm, |
|
29061
c67cc9402ba9
inhabitance goal is now stated in original form and result contracted --
wenzelm
parents:
29059
diff
changeset
|
14 |
Rep_induct: thm, Abs_induct: thm} |
35741 | 15 |
val transform_info: morphism -> info -> info |
16 |
val get_info: Proof.context -> string -> info list |
|
17 |
val get_info_global: theory -> string -> info list |
|
18 |
val interpretation: (string -> theory -> theory) -> theory -> theory |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
19 |
val add_typedef: bool -> binding * (string * sort) list * mixfix -> |
35741 | 20 |
term -> (binding * binding) option -> tactic -> local_theory -> (string * info) * local_theory |
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
21 |
val add_typedef_global: bool -> binding * (string * sort) list * mixfix -> |
30345 | 22 |
term -> (binding * binding) option -> tactic -> theory -> (string * info) * theory |
49835 | 23 |
val typedef: (binding * (string * sort) list * mixfix) * term * |
35741 | 24 |
(binding * binding) option -> local_theory -> Proof.state |
49835 | 25 |
val typedef_cmd: (binding * (string * string option) list * mixfix) * string * |
35741 | 26 |
(binding * binding) option -> local_theory -> Proof.state |
4866 | 27 |
end; |
28 |
||
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
30345
diff
changeset
|
29 |
structure Typedef: TYPEDEF = |
4866 | 30 |
struct |
31 |
||
17922 | 32 |
(** type definitions **) |
33 |
||
34 |
(* theory data *) |
|
15259 | 35 |
|
19705 | 36 |
type info = |
35994
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35840
diff
changeset
|
37 |
(*global part*) |
36107 | 38 |
{rep_type: typ, abs_type: typ, Rep_name: string, Abs_name: string, axiom_name: string} * |
35741 | 39 |
(*local part*) |
49833 | 40 |
{inhabited: thm, type_definition: thm, Rep: thm, Rep_inverse: thm, Abs_inverse: thm, |
41 |
Rep_inject: thm, Abs_inject: thm, Rep_cases: thm, Abs_cases: thm, |
|
35994
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35840
diff
changeset
|
42 |
Rep_induct: thm, Abs_induct: thm}; |
19459 | 43 |
|
35741 | 44 |
fun transform_info phi (info: info) = |
45 |
let |
|
46 |
val thm = Morphism.thm phi; |
|
49833 | 47 |
val (global_info, {inhabited, type_definition, Rep, Rep_inverse, Abs_inverse, |
48 |
Rep_inject, Abs_inject, Rep_cases, Abs_cases, Rep_induct, Abs_induct}) = info; |
|
35741 | 49 |
in |
35994
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35840
diff
changeset
|
50 |
(global_info, |
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35840
diff
changeset
|
51 |
{inhabited = thm inhabited, type_definition = thm type_definition, |
49833 | 52 |
Rep = thm Rep, Rep_inverse = thm Rep_inverse, Abs_inverse = thm Abs_inverse, |
53 |
Rep_inject = thm Rep_inject, Abs_inject = thm Abs_inject, |
|
54 |
Rep_cases = thm Rep_cases, Abs_cases = thm Abs_cases, |
|
55 |
Rep_induct = thm Rep_induct, Abs_induct = thm Abs_induct}) |
|
35741 | 56 |
end; |
57 |
||
58 |
structure Data = Generic_Data |
|
22846 | 59 |
( |
35741 | 60 |
type T = info list Symtab.table; |
15259 | 61 |
val empty = Symtab.empty; |
16458 | 62 |
val extend = I; |
35741 | 63 |
fun merge data = Symtab.merge_list (K true) data; |
22846 | 64 |
); |
15259 | 65 |
|
35741 | 66 |
val get_info = Symtab.lookup_list o Data.get o Context.Proof; |
67 |
val get_info_global = Symtab.lookup_list o Data.get o Context.Theory; |
|
68 |
||
69 |
fun put_info name info = Data.map (Symtab.cons_list (name, info)); |
|
70 |
||
71 |
||
72 |
(* global interpretation *) |
|
73 |
||
74 |
structure Typedef_Interpretation = Interpretation(type T = string val eq = op =); |
|
56375
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
75 |
|
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
76 |
fun with_repaired_path f name thy = |
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
77 |
thy |
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
78 |
|> Sign.root_path |
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
79 |
|> Sign.add_path (Long_Name.qualifier name) |
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
80 |
|> f name |
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
81 |
|> Sign.restore_naming thy; |
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
82 |
|
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
83 |
fun interpretation f = Typedef_Interpretation.interpretation (with_repaired_path f); |
35741 | 84 |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
85 |
val _ = Theory.setup Typedef_Interpretation.init; |
35741 | 86 |
|
87 |
||
88 |
(* primitive typedef axiomatization -- for fresh typedecl *) |
|
89 |
||
90 |
fun mk_inhabited A = |
|
91 |
let val T = HOLogic.dest_setT (Term.fastype_of A) |
|
92 |
in HOLogic.mk_Trueprop (HOLogic.exists_const T $ Abs ("x", T, HOLogic.mk_mem (Bound 0, A))) end; |
|
93 |
||
94 |
fun mk_typedef newT oldT RepC AbsC A = |
|
95 |
let |
|
96 |
val typedefC = |
|
97 |
Const (@{const_name type_definition}, |
|
98 |
(newT --> oldT) --> (oldT --> newT) --> HOLogic.mk_setT oldT --> HOLogic.boolT); |
|
99 |
in Logic.mk_implies (mk_inhabited A, HOLogic.mk_Trueprop (typedefC $ RepC $ AbsC $ A)) end; |
|
35134 | 100 |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
101 |
fun primitive_typedef typedef_name newT oldT Rep_name Abs_name A lthy = |
35741 | 102 |
let |
103 |
(* errors *) |
|
104 |
||
105 |
fun show_names pairs = commas_quote (map fst pairs); |
|
106 |
||
107 |
val lhs_tfrees = Term.add_tfreesT newT []; |
|
108 |
val rhs_tfrees = Term.add_tfreesT oldT []; |
|
109 |
val _ = |
|
110 |
(case fold (remove (op =)) lhs_tfrees rhs_tfrees of [] => () |
|
111 |
| extras => error ("Extra type variables in representing set: " ^ show_names extras)); |
|
112 |
||
113 |
val _ = |
|
114 |
(case Term.add_frees A [] of [] => [] |
|
115 |
| xs => error ("Illegal variables in representing set: " ^ show_names xs)); |
|
35134 | 116 |
|
35741 | 117 |
|
118 |
(* axiomatization *) |
|
119 |
||
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
120 |
val ((RepC, AbsC), consts_lthy) = lthy |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
121 |
|> Local_Theory.background_theory_result |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
122 |
(Sign.declare_const lthy ((Rep_name, newT --> oldT), NoSyn) ##>> |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
123 |
Sign.declare_const lthy ((Abs_name, oldT --> newT), NoSyn)); |
35741 | 124 |
|
125 |
val typedef_deps = Term.add_consts A []; |
|
126 |
||
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
127 |
val ((axiom_name, axiom), axiom_lthy) = consts_lthy |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
128 |
|> Local_Theory.background_theory_result |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
129 |
(Thm.add_axiom consts_lthy (typedef_name, mk_typedef newT oldT RepC AbsC A) ##> |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
130 |
Theory.add_deps consts_lthy "" (dest_Const RepC) typedef_deps ##> |
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
131 |
Theory.add_deps consts_lthy "" (dest_Const AbsC) typedef_deps); |
35741 | 132 |
|
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42361
diff
changeset
|
133 |
in ((RepC, AbsC, axiom_name, axiom), axiom_lthy) end; |
15259 | 134 |
|
135 |
||
6383 | 136 |
(* prepare_typedef *) |
137 |
||
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
138 |
fun prepare_typedef conceal prep_term (name, raw_args, mx) raw_set opt_morphs lthy = |
4866 | 139 |
let |
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
140 |
val concealed_name = name |> conceal ? Binding.conceal; |
30345 | 141 |
val bname = Binding.name_of name; |
4866 | 142 |
|
35741 | 143 |
|
144 |
(* rhs *) |
|
145 |
||
36153
1ac501e16a6a
replaced slightly odd Typedecl.predeclare_constraints by plain declaration of type arguments -- also avoid "recursive" declaration of type constructor, which can cause problems with sequential definitions B.foo = A.foo;
wenzelm
parents:
36107
diff
changeset
|
146 |
val tmp_ctxt = lthy |> fold (Variable.declare_typ o TFree) raw_args; |
1ac501e16a6a
replaced slightly odd Typedecl.predeclare_constraints by plain declaration of type arguments -- also avoid "recursive" declaration of type constructor, which can cause problems with sequential definitions B.foo = A.foo;
wenzelm
parents:
36107
diff
changeset
|
147 |
val set = prep_term tmp_ctxt raw_set; |
1ac501e16a6a
replaced slightly odd Typedecl.predeclare_constraints by plain declaration of type arguments -- also avoid "recursive" declaration of type constructor, which can cause problems with sequential definitions B.foo = A.foo;
wenzelm
parents:
36107
diff
changeset
|
148 |
val tmp_ctxt' = tmp_ctxt |> Variable.declare_term set; |
35836
9380fab5f4f7
eliminated slightly odd typedecl_wrt in favour of explicit predeclare_constraints;
wenzelm
parents:
35766
diff
changeset
|
149 |
|
21352 | 150 |
val setT = Term.fastype_of set; |
35741 | 151 |
val oldT = HOLogic.dest_setT setT handle TYPE _ => |
152 |
error ("Not a set type: " ^ quote (Syntax.string_of_typ lthy setT)); |
|
153 |
||
154 |
val goal = mk_inhabited set; |
|
42290
b1f544c84040
discontinued special treatment of structure Lexicon;
wenzelm
parents:
38757
diff
changeset
|
155 |
val goal_pat = mk_inhabited (Var (the_default (bname, 0) (Lexicon.read_variable bname), setT)); |
35741 | 156 |
|
157 |
||
158 |
(* lhs *) |
|
159 |
||
42361 | 160 |
val args = map (Proof_Context.check_tfree tmp_ctxt') raw_args; |
35741 | 161 |
val (newT, typedecl_lthy) = lthy |
49835 | 162 |
|> Typedecl.typedecl (name, args, mx) |
35741 | 163 |
||> Variable.declare_term set; |
164 |
||
56375
32e0da92c786
use same idiom as used for datatype 'size' function to name constants and theorems emerging from various type interpretations -- reduces the chances of name clashes on theory merges
blanchet
parents:
54883
diff
changeset
|
165 |
val Type (full_name, _) = newT; |
35741 | 166 |
|
167 |
||
168 |
(* axiomatization *) |
|
4866 | 169 |
|
30345 | 170 |
val (Rep_name, Abs_name) = |
171 |
(case opt_morphs of |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
172 |
NONE => (Binding.prefix_name "Rep_" concealed_name, |
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
173 |
Binding.prefix_name "Abs_" concealed_name) |
30345 | 174 |
| SOME morphs => morphs); |
10280 | 175 |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
176 |
val typedef_name = Binding.prefix_name "type_definition_" concealed_name; |
4866 | 177 |
|
49833 | 178 |
val ((RepC, AbsC, axiom_name, typedef), typedef_lthy) = typedecl_lthy |
179 |
|> primitive_typedef typedef_name newT oldT Rep_name Abs_name set; |
|
35741 | 180 |
|
181 |
val alias_lthy = typedef_lthy |
|
182 |
|> Local_Theory.const_alias Rep_name (#1 (Term.dest_Const RepC)) |
|
183 |
|> Local_Theory.const_alias Abs_name (#1 (Term.dest_Const AbsC)); |
|
6383 | 184 |
|
29056 | 185 |
|
35741 | 186 |
(* result *) |
4866 | 187 |
|
35741 | 188 |
fun note_qualify ((b, atts), th) = |
189 |
Local_Theory.note ((Binding.qualify false bname b, map (Attrib.internal o K) atts), [th]) |
|
190 |
#>> (fn (_, [th']) => th'); |
|
4866 | 191 |
|
35741 | 192 |
fun typedef_result inhabited lthy1 = |
193 |
let |
|
49833 | 194 |
val typedef' = inhabited RS typedef; |
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
49835
diff
changeset
|
195 |
fun make th = Goal.norm_result lthy1 (typedef' RS th); |
35741 | 196 |
val (((((((((((_, [type_definition]), Rep), Rep_inverse), Abs_inverse), Rep_inject), |
197 |
Abs_inject), Rep_cases), Abs_cases), Rep_induct), Abs_induct), lthy2) = lthy1 |
|
198 |
|> Local_Theory.note ((typedef_name, []), [typedef']) |
|
199 |
||>> note_qualify ((Rep_name, []), make @{thm type_definition.Rep}) |
|
200 |
||>> note_qualify ((Binding.suffix_name "_inverse" Rep_name, []), |
|
201 |
make @{thm type_definition.Rep_inverse}) |
|
202 |
||>> note_qualify ((Binding.suffix_name "_inverse" Abs_name, []), |
|
203 |
make @{thm type_definition.Abs_inverse}) |
|
204 |
||>> note_qualify ((Binding.suffix_name "_inject" Rep_name, []), |
|
205 |
make @{thm type_definition.Rep_inject}) |
|
206 |
||>> note_qualify ((Binding.suffix_name "_inject" Abs_name, []), |
|
207 |
make @{thm type_definition.Abs_inject}) |
|
208 |
||>> note_qualify ((Binding.suffix_name "_cases" Rep_name, |
|
209 |
[Rule_Cases.case_names [Binding.name_of Rep_name], Induct.cases_pred full_name]), |
|
210 |
make @{thm type_definition.Rep_cases}) |
|
211 |
||>> note_qualify ((Binding.suffix_name "_cases" Abs_name, |
|
49835 | 212 |
[Rule_Cases.case_names [Binding.name_of Abs_name], Induct.cases_type full_name]), |
35741 | 213 |
make @{thm type_definition.Abs_cases}) |
214 |
||>> note_qualify ((Binding.suffix_name "_induct" Rep_name, |
|
215 |
[Rule_Cases.case_names [Binding.name_of Rep_name], Induct.induct_pred full_name]), |
|
216 |
make @{thm type_definition.Rep_induct}) |
|
217 |
||>> note_qualify ((Binding.suffix_name "_induct" Abs_name, |
|
49835 | 218 |
[Rule_Cases.case_names [Binding.name_of Abs_name], Induct.induct_type full_name]), |
35741 | 219 |
make @{thm type_definition.Abs_induct}); |
4866 | 220 |
|
35994
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35840
diff
changeset
|
221 |
val info = |
36107 | 222 |
({rep_type = oldT, abs_type = newT, Rep_name = #1 (Term.dest_Const RepC), |
223 |
Abs_name = #1 (Term.dest_Const AbsC), axiom_name = axiom_name}, |
|
49833 | 224 |
{inhabited = inhabited, type_definition = type_definition, |
35741 | 225 |
Rep = Rep, Rep_inverse = Rep_inverse, Abs_inverse = Abs_inverse, |
226 |
Rep_inject = Rep_inject, Abs_inject = Abs_inject, Rep_cases = Rep_cases, |
|
35994
9cc3df9a606e
Typedef.info: separate global and local part, only the latter is transformed by morphisms;
wenzelm
parents:
35840
diff
changeset
|
227 |
Abs_cases = Abs_cases, Rep_induct = Rep_induct, Abs_induct = Abs_induct}); |
35741 | 228 |
in |
229 |
lthy2 |
|
45291
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
wenzelm
parents:
42381
diff
changeset
|
230 |
|> Local_Theory.declaration {syntax = false, pervasive = true} |
49835 | 231 |
(fn phi => put_info full_name (transform_info phi info)) |
232 |
|> Local_Theory.background_theory (Typedef_Interpretation.data full_name) |
|
233 |
|> pair (full_name, info) |
|
35741 | 234 |
end; |
11426
f280d4b29a2c
abtract non-emptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset
|
235 |
|
35741 | 236 |
in ((goal, goal_pat, typedef_result), alias_lthy) end |
30345 | 237 |
handle ERROR msg => |
42381
309ec68442c6
added Binding.print convenience, which includes quote already;
wenzelm
parents:
42375
diff
changeset
|
238 |
cat_error msg ("The error(s) above occurred in typedef " ^ Binding.print name); |
4866 | 239 |
|
240 |
||
29056 | 241 |
(* add_typedef: tactic interface *) |
4866 | 242 |
|
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
243 |
fun add_typedef conceal typ set opt_morphs tac lthy = |
6383 | 244 |
let |
35741 | 245 |
val ((goal, _, typedef_result), lthy') = |
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
246 |
prepare_typedef conceal Syntax.check_term typ set opt_morphs lthy; |
35741 | 247 |
val inhabited = |
248 |
Goal.prove lthy' [] [] goal (K tac) |
|
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
49835
diff
changeset
|
249 |
|> Goal.norm_result lthy' |> Thm.close_derivation; |
35741 | 250 |
in typedef_result inhabited lthy' end; |
251 |
||
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
252 |
fun add_typedef_global conceal typ set opt_morphs tac = |
38388 | 253 |
Named_Target.theory_init |
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
254 |
#> add_typedef conceal typ set opt_morphs tac |
35741 | 255 |
#> Local_Theory.exit_result_global (apsnd o transform_info); |
4866 | 256 |
|
17339 | 257 |
|
29056 | 258 |
(* typedef: proof interface *) |
6383 | 259 |
|
17339 | 260 |
local |
261 |
||
49835 | 262 |
fun gen_typedef prep_term prep_constraint ((b, raw_args, mx), set, opt_morphs) lthy = |
11822 | 263 |
let |
35840
01d7c4ba9050
allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents:
35836
diff
changeset
|
264 |
val args = map (apsnd (prep_constraint lthy)) raw_args; |
35741 | 265 |
val ((goal, goal_pat, typedef_result), lthy') = |
58239
1c5bc387bd4c
added flag to 'typedef' to allow concealed definitions
blanchet
parents:
56375
diff
changeset
|
266 |
prepare_typedef false prep_term (b, args, mx) set opt_morphs lthy; |
35741 | 267 |
fun after_qed [[th]] = snd o typedef_result th; |
36323
655e2d74de3a
modernized naming conventions of main Isar proof elements;
wenzelm
parents:
36153
diff
changeset
|
268 |
in Proof.theorem NONE after_qed [[(goal, [goal_pat])]] lthy' end; |
17339 | 269 |
|
270 |
in |
|
6383 | 271 |
|
35840
01d7c4ba9050
allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents:
35836
diff
changeset
|
272 |
val typedef = gen_typedef Syntax.check_term (K I); |
01d7c4ba9050
allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents:
35836
diff
changeset
|
273 |
val typedef_cmd = gen_typedef Syntax.read_term Typedecl.read_constraint; |
17339 | 274 |
|
19705 | 275 |
end; |
15259 | 276 |
|
277 |
||
278 |
||
6383 | 279 |
(** outer syntax **) |
280 |
||
24867 | 281 |
val _ = |
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
282 |
Outer_Syntax.local_theory_to_proof @{command_spec "typedef"} |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
283 |
"HOL type definition (requires non-emptiness proof)" |
49835 | 284 |
(Parse.type_args_constrained -- Parse.binding -- Parse.opt_mixfix -- |
285 |
(@{keyword "="} |-- Parse.term) -- |
|
286 |
Scan.option (@{keyword "morphisms"} |-- Parse.!!! (Parse.binding -- Parse.binding)) |
|
287 |
>> (fn ((((vs, t), mx), A), morphs) => fn lthy => typedef_cmd ((t, vs, mx), A, morphs) lthy)); |
|
6357 | 288 |
|
29056 | 289 |
end; |
290 |