author  wenzelm 
Tue, 16 Aug 2005 13:42:26 +0200  
changeset 17057  0934ac31985f 
parent 16645  a152d6b21c31 
child 17144  6642e0f96f44 
permissions  rwrr 
4866  1 
(* Title: HOL/Tools/typedef_package.ML 
2 
ID: $Id$ 

16458  3 
Author: Markus Wenzel and Stefan Berghofer, TU Muenchen 
4866  4 

6357  5 
Gordon/HOLstyle type definitions. 
4866  6 
*) 
7 

8 
signature TYPEDEF_PACKAGE = 

9 
sig 

5697  10 
val quiet_mode: bool ref 
5104  11 
val add_typedecls: (bstring * string list * mixfix) list > theory > theory 
11822  12 
val add_typedef_x: string > bstring * string list * mixfix > 
4866  13 
string > string list > thm list > tactic option > theory > theory 
11827  14 
val add_typedef: bool > string option > bstring * string list * mixfix > 
11822  15 
string > (bstring * bstring) option > tactic > theory > theory * 
16 
{type_definition: thm, set_def: thm option, Rep: thm, Rep_inverse: thm, 

17 
Abs_inverse: thm, Rep_inject: thm, Abs_inject: thm, Rep_cases: thm, Abs_cases: thm, 

18 
Rep_induct: thm, Abs_induct: thm} 

11827  19 
val add_typedef_i: bool > string option > bstring * string list * mixfix > 
11822  20 
term > (bstring * bstring) option > tactic > theory > theory * 
21 
{type_definition: thm, set_def: thm option, Rep: thm, Rep_inverse: thm, 

22 
Abs_inverse: thm, Rep_inject: thm, Abs_inject: thm, Rep_cases: thm, Abs_cases: thm, 

23 
Rep_induct: thm, Abs_induct: thm} 

13443  24 
val typedef_proof: (bool * string) * (bstring * string list * mixfix) * string 
25 
* (string * string) option > bool > theory > ProofHistory.T 

26 
val typedef_proof_i: (bool * string) * (bstring * string list * mixfix) * term 

27 
* (string * string) option > bool > theory > ProofHistory.T 

15259  28 
val setup: (theory > theory) list 
4866  29 
end; 
30 

31 
structure TypedefPackage: TYPEDEF_PACKAGE = 

32 
struct 

33 

34 

10280  35 
(** theory context references **) 
36 

11608  37 
val type_definitionN = "Typedef.type_definition"; 
10280  38 

13413  39 
val Rep = thm "type_definition.Rep"; 
40 
val Rep_inverse = thm "type_definition.Rep_inverse"; 

41 
val Abs_inverse = thm "type_definition.Abs_inverse"; 

42 
val Rep_inject = thm "type_definition.Rep_inject"; 

43 
val Abs_inject = thm "type_definition.Abs_inject"; 

44 
val Rep_cases = thm "type_definition.Rep_cases"; 

45 
val Abs_cases = thm "type_definition.Abs_cases"; 

46 
val Rep_induct = thm "type_definition.Rep_induct"; 

47 
val Abs_induct = thm "type_definition.Abs_induct"; 

10280  48 

49 

50 

15259  51 
(** theory data **) 
52 

16458  53 
structure TypedefData = TheoryDataFun 
54 
(struct 

15259  55 
val name = "HOL/typedef"; 
56 
type T = (typ * typ * string * string) Symtab.table; 

57 
val empty = Symtab.empty; 

58 
val copy = I; 

16458  59 
val extend = I; 
60 
fun merge _ (tabs: T * T) = Symtab.merge (op =) tabs; 

61 
fun print _ _ = (); 

62 
end); 

15259  63 

64 
fun put_typedef newT oldT Abs_name Rep_name thy = 

65 
TypedefData.put (Symtab.update_new 

66 
((fst (dest_Type newT), (newT, oldT, Abs_name, Rep_name)), 

67 
TypedefData.get thy)) thy; 

68 

69 

70 

5104  71 
(** type declarations **) 
72 

73 
fun add_typedecls decls thy = 

74 
let 

75 
fun arity_of (raw_name, args, mx) = 

16458  76 
(Sign.full_name thy (Syntax.type_name raw_name mx), 
77 
replicate (length args) HOLogic.typeS, HOLogic.typeS); 

5104  78 
in 
8141  79 
if can (Theory.assert_super HOL.thy) thy then 
16458  80 
thy > Theory.add_typedecls decls 
8141  81 
> Theory.add_arities_i (map arity_of decls) 
16458  82 
else thy > Theory.add_typedecls decls 
5104  83 
end; 
84 

85 

86 

87 
(** type definitions **) 

88 

5697  89 
(* messages *) 
90 

91 
val quiet_mode = ref false; 

92 
fun message s = if ! quiet_mode then () else writeln s; 

93 

94 

11426
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

95 
(* prove_nonempty  tactical version *) (*exception ERROR*) 
4866  96 

11827  97 
fun prove_nonempty thy cset goal (witn1_tac, witn_names, witn_thms, witn2_tac) = 
6383  98 
let 
99 
val is_def = Logic.is_equals o #prop o Thm.rep_thm; 

16486  100 
val thms = PureThy.get_thmss thy (map Name witn_names) @ witn_thms; 
4866  101 
val tac = 
11827  102 
witn1_tac THEN 
15570  103 
TRY (rewrite_goals_tac (List.filter is_def thms)) THEN 
4866  104 
TRY (REPEAT_FIRST (resolve_tac (filter_out is_def thms))) THEN 
15570  105 
getOpt (witn2_tac, TRY (ALLGOALS (CLASET' blast_tac))); 
4866  106 
in 
6383  107 
message ("Proving nonemptiness of set " ^ quote (string_of_cterm cset) ^ " ..."); 
16458  108 
Tactic.prove thy [] [] goal (K tac) 
109 
end 

110 
handle ERROR => error ("Failed to prove nonemptiness of " ^ quote (string_of_cterm cset)); 

4866  111 

112 

6383  113 
(* prepare_typedef *) 
114 

16458  115 
fun read_term thy used s = 
116 
#1 (Thm.read_def_cterm (thy, K NONE, K NONE) used true (s, HOLogic.typeT)); 

4866  117 

16458  118 
fun cert_term thy _ t = Thm.cterm_of thy t handle TERM (msg, _) => error msg; 
6383  119 

120 
fun err_in_typedef name = 

121 
error ("The error(s) above occurred in typedef " ^ quote name); 

122 

11822  123 
fun prepare_typedef prep_term def name (t, vs, mx) raw_set opt_morphs thy = 
4866  124 
let 
11608  125 
val _ = Theory.requires thy "Typedef" "typedefs"; 
16458  126 
val full = Sign.full_name thy; 
4866  127 

128 
(*rhs*) 

10280  129 
val full_name = full name; 
16458  130 
val cset = prep_term thy vs raw_set; 
6383  131 
val {T = setT, t = set, ...} = Thm.rep_cterm cset; 
4866  132 
val rhs_tfrees = term_tfrees set; 
133 
val oldT = HOLogic.dest_setT setT handle TYPE _ => 

16458  134 
error ("Not a set type: " ^ quote (Sign.string_of_typ thy setT)); 
11426
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

135 
fun mk_nonempty A = 
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

136 
HOLogic.mk_Trueprop (HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), A))); 
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

137 
val goal = mk_nonempty set; 
11744  138 
val vname = take_suffix Symbol.is_digit (Symbol.explode name) 
14819  139 
> apfst implode > apsnd (#1 o Library.read_int); 
11744  140 
val goal_pat = mk_nonempty (Var (vname, setT)); 
4866  141 

142 
(*lhs*) 

15570  143 
val lhs_tfrees = map (fn v => (v, getOpt (assoc (rhs_tfrees, v), HOLogic.typeS))) vs; 
4866  144 
val tname = Syntax.type_name t mx; 
10280  145 
val full_tname = full tname; 
146 
val newT = Type (full_tname, map TFree lhs_tfrees); 

4866  147 

15570  148 
val (Rep_name, Abs_name) = getOpt (opt_morphs, ("Rep_" ^ name, "Abs_" ^ name)); 
10280  149 
val setC = Const (full_name, setT); 
150 
val RepC = Const (full Rep_name, newT > oldT); 

151 
val AbsC = Const (full Abs_name, oldT > newT); 

4866  152 
val x_new = Free ("x", newT); 
153 
val y_old = Free ("y", oldT); 

10280  154 

11822  155 
val set' = if def then setC else set; 
4866  156 

10280  157 
val typedef_name = "type_definition_" ^ name; 
158 
val typedefC = 

159 
Const (type_definitionN, (newT > oldT) > (oldT > newT) > setT > HOLogic.boolT); 

11426
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

160 
val typedef_prop = 
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

161 
Logic.mk_implies (goal, HOLogic.mk_Trueprop (typedefC $ RepC $ AbsC $ set')); 
4866  162 

11822  163 
fun typedef_result (theory, nonempty) = 
6383  164 
theory 
15259  165 
> put_typedef newT oldT (full Abs_name) (full Rep_name) 
6383  166 
> add_typedecls [(t, vs, mx)] 
167 
> Theory.add_consts_i 

11822  168 
((if def then [(name, setT, NoSyn)] else []) @ 
6383  169 
[(Rep_name, newT > oldT, NoSyn), 
170 
(Abs_name, oldT > newT, NoSyn)]) 

15531  171 
> (if def then (apsnd (SOME o hd) oo (PureThy.add_defs_i false o map Thm.no_attributes)) 
11822  172 
[Logic.mk_defpair (setC, set)] 
15531  173 
else rpair NONE) 
14570  174 
>>> PureThy.add_axioms_i [((typedef_name, typedef_prop), 
11727
a27150cc8fa5
test: use SkipProof.make_thm instead of Thm.assume;
wenzelm
parents:
11608
diff
changeset

175 
[apsnd (fn cond_axm => Drule.standard (nonempty RS cond_axm))])] 
14570  176 
>> Theory.add_finals_i false [RepC, AbsC] 
177 
> (fn (theory', (set_def, [type_definition])) => 

11822  178 
let 
179 
fun make th = Drule.standard (th OF [type_definition]); 

180 
val (theory'', [Rep, Rep_inverse, Abs_inverse, Rep_inject, Abs_inject, 

181 
Rep_cases, Abs_cases, Rep_induct, Abs_induct]) = 

12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12043
diff
changeset

182 
theory' 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12043
diff
changeset

183 
> Theory.add_path name 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12043
diff
changeset

184 
> PureThy.add_thms 
11822  185 
([((Rep_name, make Rep), []), 
186 
((Rep_name ^ "_inverse", make Rep_inverse), []), 

187 
((Abs_name ^ "_inverse", make Abs_inverse), []), 

188 
((Rep_name ^ "_inject", make Rep_inject), []), 

189 
((Abs_name ^ "_inject", make Abs_inject), []), 

190 
((Rep_name ^ "_cases", make Rep_cases), 

191 
[RuleCases.case_names [Rep_name], InductAttrib.cases_set_global full_name]), 

192 
((Abs_name ^ "_cases", make Abs_cases), 

193 
[RuleCases.case_names [Abs_name], InductAttrib.cases_type_global full_tname]), 

194 
((Rep_name ^ "_induct", make Rep_induct), 

195 
[RuleCases.case_names [Rep_name], InductAttrib.induct_set_global full_name]), 

196 
((Abs_name ^ "_induct", make Abs_induct), 

12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12043
diff
changeset

197 
[RuleCases.case_names [Abs_name], InductAttrib.induct_type_global full_tname])]) 
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
12043
diff
changeset

198 
>> Theory.parent_path; 
11822  199 
val result = {type_definition = type_definition, set_def = set_def, 
200 
Rep = Rep, Rep_inverse = Rep_inverse, Abs_inverse = Abs_inverse, 

201 
Rep_inject = Rep_inject, Abs_inject = Abs_inject, Rep_cases = Rep_cases, 

202 
Abs_cases = Abs_cases, Rep_induct = Rep_induct, Abs_induct = Abs_induct}; 

203 
in ((theory'', type_definition), result) end); 

6383  204 

4866  205 

206 
(* errors *) 

207 

208 
fun show_names pairs = commas_quote (map fst pairs); 

209 

210 
val illegal_vars = 

211 
if null (term_vars set) andalso null (term_tvars set) then [] 

212 
else ["Illegal schematic variable(s) on rhs"]; 

213 

214 
val dup_lhs_tfrees = 

215 
(case duplicates lhs_tfrees of [] => [] 

216 
 dups => ["Duplicate type variables on lhs: " ^ show_names dups]); 

217 

218 
val extra_rhs_tfrees = 

219 
(case gen_rems (op =) (rhs_tfrees, lhs_tfrees) of [] => [] 

220 
 extras => ["Extra type variables on rhs: " ^ show_names extras]); 

221 

222 
val illegal_frees = 

223 
(case term_frees set of [] => [] 

224 
 xs => ["Illegal variables on rhs: " ^ show_names (map dest_Free xs)]); 

225 

226 
val errs = illegal_vars @ dup_lhs_tfrees @ extra_rhs_tfrees @ illegal_frees; 

11426
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

227 
val _ = if null errs then () else error (cat_lines errs); 
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

228 

f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

229 
(*test theory errors now!*) 
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

230 
val test_thy = Theory.copy thy; 
11727
a27150cc8fa5
test: use SkipProof.make_thm instead of Thm.assume;
wenzelm
parents:
11608
diff
changeset

231 
val _ = (test_thy, 
11822  232 
setmp quick_and_dirty true (SkipProof.make_thm test_thy) goal) > typedef_result; 
11426
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

233 

11822  234 
in (cset, goal, goal_pat, typedef_result) end 
11426
f280d4b29a2c
abtract nonemptiness statements (no longer use Eps);
wenzelm
parents:
10697
diff
changeset

235 
handle ERROR => err_in_typedef name; 
4866  236 

237 

6383  238 
(* add_typedef interfaces *) 
4866  239 

11827  240 
fun gen_typedef prep_term def name typ set opt_morphs tac1 names thms tac2 thy = 
6383  241 
let 
11822  242 
val (cset, goal, _, typedef_result) = 
243 
prepare_typedef prep_term def name typ set opt_morphs thy; 

11827  244 
val non_empty = prove_nonempty thy cset goal (tac1, names, thms, tac2); 
11822  245 
val ((thy', _), result) = (thy, non_empty) > typedef_result; 
246 
in (thy', result) end; 

4866  247 

11827  248 
fun sane_typedef prep_term def opt_name typ set opt_morphs tac = 
249 
gen_typedef prep_term def 

15570  250 
(getOpt (opt_name, #1 typ)) typ set opt_morphs all_tac [] [] (SOME tac); 
11822  251 

252 
fun add_typedef_x name typ set names thms tac = 

15531  253 
#1 o gen_typedef read_term true name typ set NONE (Tactic.rtac exI 1) names thms tac; 
11822  254 

255 
val add_typedef = sane_typedef read_term; 

256 
val add_typedef_i = sane_typedef cert_term; 

4866  257 

258 

6383  259 
(* typedef_proof interface *) 
260 

13443  261 
fun gen_typedef_proof prep_term ((def, name), typ, set, opt_morphs) int thy = 
11822  262 
let 
263 
val (_, goal, goal_pat, att_result) = 

13443  264 
prepare_typedef prep_term def name typ set opt_morphs thy; 
11822  265 
val att = #1 o att_result; 
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12694
diff
changeset

266 
in thy > IsarThy.theorem_i Drule.internalK (("", [att]), (goal, ([goal_pat], []))) int end; 
6383  267 

268 
val typedef_proof = gen_typedef_proof read_term; 

269 
val typedef_proof_i = gen_typedef_proof cert_term; 

6357  270 

271 

6383  272 

15259  273 
(** trivial code generator **) 
274 

16645  275 
fun typedef_codegen thy defs gr dep thyname brack t = 
15259  276 
let 
16645  277 
fun get_name (Type (tname, _)) = tname 
278 
 get_name _ = ""; 

15259  279 
fun mk_fun s T ts = 
280 
let 

16645  281 
val (gr', _) = Codegen.invoke_tycodegen thy defs dep thyname false (gr, T); 
15259  282 
val (gr'', ps) = 
16645  283 
foldl_map (Codegen.invoke_codegen thy defs dep thyname true) (gr', ts); 
284 
val id = Codegen.mk_const_id thy 

285 
thyname (Codegen.thyname_of_type (get_name T) thy) s 

15531  286 
in SOME (gr'', Codegen.mk_app brack (Pretty.str id) ps) end; 
15570  287 
fun lookup f T = getOpt (Option.map f (Symtab.lookup 
288 
(TypedefData.get thy, get_name T)), "") 

15259  289 
in 
290 
(case strip_comb t of 

291 
(Const (s, Type ("fun", [T, U])), ts) => 

292 
if lookup #4 T = s andalso 

293 
is_none (Codegen.get_assoc_type thy (get_name T)) 

294 
then mk_fun s T ts 

295 
else if lookup #3 U = s andalso 

296 
is_none (Codegen.get_assoc_type thy (get_name U)) 

297 
then mk_fun s U ts 

15531  298 
else NONE 
299 
 _ => NONE) 

15259  300 
end; 
301 

302 
fun mk_tyexpr [] s = Pretty.str s 

303 
 mk_tyexpr [p] s = Pretty.block [p, Pretty.str (" " ^ s)] 

304 
 mk_tyexpr ps s = Pretty.list "(" (") " ^ s) ps; 

305 

16645  306 
fun typedef_tycodegen thy defs gr dep thyname brack (Type (s, Ts)) = 
15259  307 
(case Symtab.lookup (TypedefData.get thy, s) of 
15531  308 
NONE => NONE 
309 
 SOME (newT as Type (tname, Us), oldT, Abs_name, Rep_name) => 

15570  310 
if isSome (Codegen.get_assoc_type thy tname) then NONE else 
15259  311 
let 
16645  312 
val thyname' = Codegen.thyname_of_type tname thy; 
313 
val Abs_id = Codegen.mk_const_id thy thyname' thyname' Abs_name; 

314 
val Rep_id = Codegen.mk_const_id thy thyname' thyname' Rep_name; 

315 
val ty_id = Codegen.mk_type_id thy thyname' thyname' s; 

316 
val ty_call_id = Codegen.mk_type_id thy thyname thyname' s; 

15259  317 
val (gr', qs) = foldl_map 
16645  318 
(Codegen.invoke_tycodegen thy defs dep thyname (length Ts = 1)) (gr, Ts); 
319 
val gr'' = Graph.add_edge (Abs_name, dep) gr' handle Graph.UNDEF _ => 

15259  320 
let 
321 
val (gr'', p :: ps) = foldl_map 

16645  322 
(Codegen.invoke_tycodegen thy defs Abs_name thyname' false) 
323 
(Graph.add_edge (Abs_name, dep) 

324 
(Graph.new_node (Abs_name, (NONE, "", "")) gr'), oldT :: Us); 

15259  325 
val s = 
326 
Pretty.string_of (Pretty.block [Pretty.str "datatype ", 

327 
mk_tyexpr ps ty_id, 

328 
Pretty.str " =", Pretty.brk 1, Pretty.str (Abs_id ^ " of"), 

329 
Pretty.brk 1, p, Pretty.str ";"]) ^ "\n\n" ^ 

330 
Pretty.string_of (Pretty.block [Pretty.str ("fun " ^ Rep_id), 

331 
Pretty.brk 1, Pretty.str ("(" ^ Abs_id), Pretty.brk 1, 

332 
Pretty.str "x) = x;"]) ^ "\n\n" ^ 

333 
(if "term_of" mem !Codegen.mode then 

334 
Pretty.string_of (Pretty.block [Pretty.str "fun ", 

16645  335 
Codegen.mk_term_of thy thyname' false newT, Pretty.brk 1, 
15259  336 
Pretty.str ("(" ^ Abs_id), Pretty.brk 1, 
337 
Pretty.str "x) =", Pretty.brk 1, 

338 
Pretty.block [Pretty.str ("Const (\"" ^ Abs_name ^ "\","), 

339 
Pretty.brk 1, Codegen.mk_type false (oldT > newT), 

340 
Pretty.str ")"], Pretty.str " $", Pretty.brk 1, 

16645  341 
Codegen.mk_term_of thy thyname' false oldT, Pretty.brk 1, 
15259  342 
Pretty.str "x;"]) ^ "\n\n" 
343 
else "") ^ 

344 
(if "test" mem !Codegen.mode then 

345 
Pretty.string_of (Pretty.block [Pretty.str "fun ", 

16645  346 
Codegen.mk_gen thy thyname' false [] "" newT, Pretty.brk 1, 
15259  347 
Pretty.str "i =", Pretty.brk 1, 
348 
Pretty.block [Pretty.str (Abs_id ^ " ("), 

16645  349 
Codegen.mk_gen thy thyname' false [] "" oldT, Pretty.brk 1, 
15259  350 
Pretty.str "i);"]]) ^ "\n\n" 
351 
else "") 

16645  352 
in Graph.map_node Abs_name (K (NONE, thyname', s)) gr'' end 
15259  353 
in 
16645  354 
SOME (gr'', mk_tyexpr qs ty_call_id) 
15259  355 
end) 
16645  356 
 typedef_tycodegen thy defs gr dep thyname brack _ = NONE; 
15259  357 

358 
val setup = 

359 
[TypedefData.init, 

360 
Codegen.add_codegen "typedef" typedef_codegen, 

361 
Codegen.add_tycodegen "typedef" typedef_tycodegen]; 

362 

363 

364 

6383  365 
(** outer syntax **) 
366 

17057  367 
local structure P = OuterParse and K = OuterKeyword in 
6383  368 

6357  369 
val typedeclP = 
12624  370 
OuterSyntax.command "typedecl" "type declaration (HOL)" K.thy_decl 
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12694
diff
changeset

371 
(P.type_args  P.name  P.opt_infix >> (fn ((vs, t), mx) => 
6357  372 
Toplevel.theory (add_typedecls [(t, vs, mx)]))); 
373 

6723  374 

6383  375 
val typedef_proof_decl = 
16126
3ba9eb7ea366
fixed outer syntax: allow type_args with parentheses;
wenzelm
parents:
15570
diff
changeset

376 
Scan.optional (P.$$$ "("  
3ba9eb7ea366
fixed outer syntax: allow type_args with parentheses;
wenzelm
parents:
15570
diff
changeset

377 
((P.$$$ "open" >> K false)  Scan.option P.name  P.name >> (fn s => (true, SOME s))) 
3ba9eb7ea366
fixed outer syntax: allow type_args with parentheses;
wenzelm
parents:
15570
diff
changeset

378 
 P.$$$ ")") (true, NONE)  
11744  379 
(P.type_args  P.name)  P.opt_infix  (P.$$$ "="  P.term)  
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12694
diff
changeset

380 
Scan.option (P.$$$ "morphisms"  P.!!! (P.name  P.name)); 
6357  381 

13443  382 
fun mk_typedef_proof ((((((def, opt_name), (vs, t)), mx), A), morphs)) = 
15570  383 
typedef_proof ((def, getOpt (opt_name, Syntax.type_name t mx)), (t, vs, mx), A, morphs); 
6357  384 

385 
val typedefP = 

6723  386 
OuterSyntax.command "typedef" "HOL type definition (requires nonemptiness proof)" K.thy_goal 
6383  387 
(typedef_proof_decl >> (Toplevel.print oo (Toplevel.theory_to_proof o mk_typedef_proof))); 
6357  388 

6723  389 

11744  390 
val _ = OuterSyntax.add_keywords ["morphisms"]; 
6357  391 
val _ = OuterSyntax.add_parsers [typedeclP, typedefP]; 
392 

4866  393 
end; 
6383  394 

395 
end; 