| author | wenzelm |
| Wed, 19 Dec 2007 16:52:26 +0100 | |
| changeset 25709 | 43a1f08c5a29 |
| parent 25666 | f46ed5b333fd |
| permissions | -rw-r--r-- |
| 22525 | 1 |
(* Title: HOL/Library/Pure_term.thy |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann, TU Muenchen |
|
4 |
*) |
|
5 |
||
| 25666 | 6 |
header {* Partial reflection of the Pure term algebra in HOL *}
|
| 22525 | 7 |
|
8 |
theory Pure_term |
|
|
24994
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
9 |
imports Code_Message |
| 22525 | 10 |
begin |
11 |
||
| 25666 | 12 |
subsection {* Definitions and syntax *}
|
| 22525 | 13 |
|
|
24994
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
14 |
types vname = message_string; |
|
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
15 |
types "class" = message_string; |
| 22525 | 16 |
types sort = "class list" |
17 |
||
18 |
datatype "typ" = |
|
| 25666 | 19 |
Type message_string "typ list" |
20 |
| TFree vname sort |
|
| 22525 | 21 |
|
22 |
abbreviation |
|
| 25666 | 23 |
Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" where |
24 |
"Fun ty1 ty2 \<equiv> Type (STR ''fun'') [ty1, ty2]" |
|
25 |
||
26 |
locale (open) pure_term_syntax = |
|
27 |
fixes pure_term_Type :: "message_string \<Rightarrow> typ list \<Rightarrow> typ" (infixl "{\<struct>}" 120)
|
|
28 |
and pure_term_TFree :: "vname \<Rightarrow> sort \<Rightarrow> typ" ("\<lbrace>_\<Colon>_\<rbrace>" [118, 118] 117)
|
|
29 |
and pure_term_Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" (infixr "\<rightarrow>" 114) |
|
30 |
||
31 |
parse_translation {*
|
|
32 |
let |
|
33 |
fun Type_tr [tyco, tys] = Lexicon.const @{const_syntax Type} $ tyco $ tys
|
|
34 |
| Type_tr ts = raise TERM ("Type_tr", ts);
|
|
35 |
fun TFree_tr [v, sort] = Lexicon.const @{const_syntax TFree} $ v $ sort
|
|
36 |
| TFree_tr ts = raise TERM ("TFree_tr", ts);
|
|
37 |
fun Fun_tr [ty1, ty2] = Lexicon.const @{const_syntax Fun} $ ty1 $ ty2
|
|
38 |
| Fun_tr ts = raise TERM("Fun_tr", ts);
|
|
39 |
in [ |
|
40 |
("\\<^fixed>pure_term_Type", Type_tr),
|
|
41 |
("\\<^fixed>pure_term_TFree", TFree_tr),
|
|
42 |
("\\<^fixed>pure_term_Fun", Fun_tr)
|
|
43 |
] end |
|
44 |
*} |
|
45 |
||
46 |
notation (output) |
|
47 |
Type (infixl "{\<struct>}" 120)
|
|
48 |
and |
|
49 |
TFree ("\<lbrace>_\<Colon>_\<rbrace>" [118, 118] 117)
|
|
50 |
and |
|
51 |
Fun (infixr "\<rightarrow>" 114) |
|
| 22525 | 52 |
|
53 |
datatype "term" = |
|
|
24994
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
54 |
Const message_string "typ" (infix "\<Colon>\<subseteq>" 112) |
| 22525 | 55 |
| Fix vname "typ" (infix ":\<epsilon>" 112) |
56 |
| App "term" "term" (infixl "\<bullet>" 110) |
|
57 |
| Abs "vname \<times> typ" "term" (infixr "\<mapsto>" 111) |
|
58 |
| Bnd nat |
|
59 |
||
60 |
abbreviation |
|
61 |
Apps :: "term \<Rightarrow> term list \<Rightarrow> term" (infixl "{\<bullet>}" 110) where
|
|
62 |
"t {\<bullet>} ts \<equiv> foldl (op \<bullet>) t ts"
|
|
63 |
abbreviation |
|
64 |
Abss :: "(vname \<times> typ) list \<Rightarrow> term \<Rightarrow> term" (infixr "{\<mapsto>}" 111) where
|
|
65 |
"vs {\<mapsto>} t \<equiv> foldr (op \<mapsto>) vs t"
|
|
66 |
||
67 |
||
68 |
subsection {* ML interface *}
|
|
69 |
||
70 |
ML {*
|
|
71 |
structure Pure_term = |
|
72 |
struct |
|
73 |
||
|
24994
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
74 |
val mk_sort = HOLogic.mk_list @{typ class} o map Message_String.mk;
|
| 22525 | 75 |
|
76 |
fun mk_typ f (Type (tyco, tys)) = |
|
|
24994
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
77 |
@{term Type} $ Message_String.mk tyco
|
| 22525 | 78 |
$ HOLogic.mk_list @{typ typ} (map (mk_typ f) tys)
|
79 |
| mk_typ f (TFree v) = |
|
80 |
f v; |
|
81 |
||
82 |
fun mk_term f g (Const (c, ty)) = |
|
|
24994
c385c4eabb3b
consolidated naming conventions for code generator theories
haftmann
parents:
23854
diff
changeset
|
83 |
@{term Const} $ Message_String.mk c $ g ty
|
| 22525 | 84 |
| mk_term f g (t1 $ t2) = |
85 |
@{term App} $ mk_term f g t1 $ mk_term f g t2
|
|
86 |
| mk_term f g (Free v) = f v; |
|
87 |
||
88 |
end; |
|
89 |
*} |
|
90 |
||
91 |
||
92 |
subsection {* Code generator setup *}
|
|
93 |
||
| 22553 | 94 |
lemma [code func]: |
| 25666 | 95 |
includes pure_term_syntax |
96 |
shows "tyco1 {\<struct>} tys1 = tyco2 {\<struct>} tys2 \<longleftrightarrow> tyco1 = tyco2
|
|
| 22553 | 97 |
\<and> list_all2 (op =) tys1 tys2" |
98 |
by (auto simp add: list_all2_eq [symmetric]) |
|
99 |
||
| 23063 | 100 |
code_datatype Const App Fix |
| 22525 | 101 |
|
| 22845 | 102 |
lemmas [code func del] = term.recs term.cases term.size |
103 |
lemma [code func, code func del]: "(t1\<Colon>term) = t2 \<longleftrightarrow> t1 = t2" .. |
|
| 22525 | 104 |
|
105 |
code_type "typ" and "term" |
|
106 |
(SML "Term.typ" and "Term.term") |
|
107 |
||
| 25666 | 108 |
code_const Type and TFree |
| 22525 | 109 |
(SML "Term.Type/ (_, _)" and "Term.TFree/ (_, _)") |
110 |
||
111 |
code_const Const and App and Fix |
|
| 23063 | 112 |
(SML "Term.Const/ (_, _)" and "Term.$/ (_, _)" and "Term.Free/ (_, _)") |
| 22804 | 113 |
|
| 22525 | 114 |
code_reserved SML Term |
115 |
||
| 22665 | 116 |
end |