4 *) |
4 *) |
5 |
5 |
6 header {* Embedding (a subset of) the Pure term algebra in HOL *} |
6 header {* Embedding (a subset of) the Pure term algebra in HOL *} |
7 |
7 |
8 theory Pure_term |
8 theory Pure_term |
9 imports ML_String |
9 imports Code_Message |
10 begin |
10 begin |
11 |
11 |
12 subsection {* Definitions *} |
12 subsection {* Definitions *} |
13 |
13 |
14 types vname = ml_string; |
14 types vname = message_string; |
15 types "class" = ml_string; |
15 types "class" = message_string; |
16 types sort = "class list" |
16 types sort = "class list" |
17 |
17 |
18 datatype "typ" = |
18 datatype "typ" = |
19 Type ml_string "typ list" (infix "{\<struct>}" 120) |
19 Type message_string "typ list" (infix "{\<struct>}" 120) |
20 | TFix vname sort (infix "\<Colon>\<epsilon>" 117) |
20 | TFix vname sort (infix "\<Colon>\<epsilon>" 117) |
21 |
21 |
22 abbreviation |
22 abbreviation |
23 Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" (infixr "\<rightarrow>" 115) where |
23 Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" (infixr "\<rightarrow>" 115) where |
24 "ty1 \<rightarrow> ty2 \<equiv> Type (STR ''fun'') [ty1, ty2]" |
24 "ty1 \<rightarrow> ty2 \<equiv> Type (STR ''fun'') [ty1, ty2]" |
25 abbreviation |
25 abbreviation |
26 Funs :: "typ list \<Rightarrow> typ \<Rightarrow> typ" (infixr "{\<rightarrow>}" 115) where |
26 Funs :: "typ list \<Rightarrow> typ \<Rightarrow> typ" (infixr "{\<rightarrow>}" 115) where |
27 "tys {\<rightarrow>} ty \<equiv> foldr (op \<rightarrow>) tys ty" |
27 "tys {\<rightarrow>} ty \<equiv> foldr (op \<rightarrow>) tys ty" |
28 |
28 |
29 datatype "term" = |
29 datatype "term" = |
30 Const ml_string "typ" (infix "\<Colon>\<subseteq>" 112) |
30 Const message_string "typ" (infix "\<Colon>\<subseteq>" 112) |
31 | Fix vname "typ" (infix ":\<epsilon>" 112) |
31 | Fix vname "typ" (infix ":\<epsilon>" 112) |
32 | App "term" "term" (infixl "\<bullet>" 110) |
32 | App "term" "term" (infixl "\<bullet>" 110) |
33 | Abs "vname \<times> typ" "term" (infixr "\<mapsto>" 111) |
33 | Abs "vname \<times> typ" "term" (infixr "\<mapsto>" 111) |
34 | Bnd nat |
34 | Bnd nat |
35 |
35 |
45 |
45 |
46 ML {* |
46 ML {* |
47 structure Pure_term = |
47 structure Pure_term = |
48 struct |
48 struct |
49 |
49 |
50 val mk_sort = HOLogic.mk_list @{typ class} o map ML_String.mk; |
50 val mk_sort = HOLogic.mk_list @{typ class} o map Message_String.mk; |
51 |
51 |
52 fun mk_typ f (Type (tyco, tys)) = |
52 fun mk_typ f (Type (tyco, tys)) = |
53 @{term Type} $ ML_String.mk tyco |
53 @{term Type} $ Message_String.mk tyco |
54 $ HOLogic.mk_list @{typ typ} (map (mk_typ f) tys) |
54 $ HOLogic.mk_list @{typ typ} (map (mk_typ f) tys) |
55 | mk_typ f (TFree v) = |
55 | mk_typ f (TFree v) = |
56 f v; |
56 f v; |
57 |
57 |
58 fun mk_term f g (Const (c, ty)) = |
58 fun mk_term f g (Const (c, ty)) = |
59 @{term Const} $ ML_String.mk c $ g ty |
59 @{term Const} $ Message_String.mk c $ g ty |
60 | mk_term f g (t1 $ t2) = |
60 | mk_term f g (t1 $ t2) = |
61 @{term App} $ mk_term f g t1 $ mk_term f g t2 |
61 @{term App} $ mk_term f g t1 $ mk_term f g t2 |
62 | mk_term f g (Free v) = f v; |
62 | mk_term f g (Free v) = f v; |
63 |
63 |
64 end; |
64 end; |