author | haftmann |
Fri, 01 Sep 2006 08:36:51 +0200 | |
changeset 20453 | 855f07fabd76 |
parent 20400 | 0ad2f3bbd4f0 |
child 21079 | 747d716e98d0 |
permissions | -rw-r--r-- |
20400 | 1 |
(* ID: $Id$ |
2 |
Author: Florian Haftmann, TU Muenchen |
|
3 |
*) |
|
4 |
||
5 |
header {* Embedding (a subset of) the Pure term algebra in HOL *} |
|
6 |
||
7 |
theory CodeEmbed |
|
8 |
imports Main MLString |
|
9 |
begin |
|
10 |
||
11 |
section {* Embedding (a subset of) the Pure term algebra in HOL *} |
|
12 |
||
13 |
||
14 |
subsection {* Definitions *} |
|
15 |
||
16 |
types vname = ml_string; |
|
17 |
types "class" = ml_string; |
|
18 |
types sort = "class list" |
|
19 |
||
20 |
datatype "typ" = |
|
21 |
Type ml_string "typ list" (infix "{\<struct>}" 120) |
|
22 |
| TFix vname sort (infix "\<Colon>\<epsilon>" 117) |
|
23 |
||
24 |
abbreviation |
|
25 |
Fun :: "typ \<Rightarrow> typ \<Rightarrow> typ" (infixr "\<rightarrow>" 115) |
|
26 |
"ty1 \<rightarrow> ty2 \<equiv> Type (STR ''fun'') [ty1, ty2]" |
|
27 |
Funs :: "typ list \<Rightarrow> typ \<Rightarrow> typ" (infixr "{\<rightarrow>}" 115) |
|
28 |
"tys {\<rightarrow>} ty \<equiv> foldr (op \<rightarrow>) tys ty" |
|
29 |
||
30 |
datatype "term" = |
|
31 |
Const ml_string "typ" (infix "\<Colon>\<subseteq>" 112) |
|
32 |
| Fix vname "typ" (infix ":\<epsilon>" 112) |
|
33 |
| App "term" "term" (infixl "\<bullet>" 110) |
|
34 |
||
35 |
abbreviation |
|
36 |
Apps :: "term \<Rightarrow> term list \<Rightarrow> term" (infixl "{\<bullet>}" 110) |
|
37 |
"t {\<bullet>} ts \<equiv> foldl (op \<bullet>) t ts" |
|
38 |
||
39 |
||
40 |
subsection {* ML interface *} |
|
41 |
||
42 |
ML {* |
|
43 |
structure Embed = |
|
44 |
struct |
|
45 |
||
46 |
local |
|
47 |
val thy = the_context (); |
|
48 |
val const_Type = Sign.intern_const thy "Type"; |
|
49 |
val const_TFix = Sign.intern_const thy "TFix"; |
|
50 |
val const_Const = Sign.intern_const thy "Const"; |
|
51 |
val const_App = Sign.intern_const thy "App"; |
|
52 |
val const_Fix = Sign.intern_const thy "Fix"; |
|
53 |
in |
|
54 |
val typ_vname = Type (Sign.intern_type thy "vname", []); |
|
55 |
val typ_class = Type (Sign.intern_type thy "class", []); |
|
56 |
val typ_sort = Type (Sign.intern_type thy "sort", []); |
|
57 |
val typ_typ = Type (Sign.intern_type thy "typ", []); |
|
58 |
val typ_term = Type (Sign.intern_type thy "term", []); |
|
59 |
val term_sort = HOList.term_list typ_class MLString.term_ml_string; |
|
60 |
fun term_typ f (Type (tyco, tys)) = |
|
61 |
Const (const_Type, MLString.typ_ml_string --> HOList.typ_list typ_typ --> typ_typ) |
|
62 |
$ MLString.term_ml_string tyco $ HOList.term_list typ_typ (term_typ f) tys |
|
63 |
| term_typ f (TFree v) = |
|
64 |
f v; |
|
65 |
fun term_term f g (Const (c, ty)) = |
|
66 |
Const (const_Const, MLString.typ_ml_string --> typ_typ --> typ_term) |
|
67 |
$ MLString.term_ml_string c $ g ty |
|
68 |
| term_term f g (t1 $ t2) = |
|
69 |
Const (const_App, typ_term --> typ_term --> typ_term) |
|
70 |
$ term_term f g t1 $ term_term f g t2 |
|
71 |
| term_term f g (Free v) = f v; |
|
72 |
end; |
|
73 |
||
74 |
end; |
|
75 |
*} |
|
76 |
||
77 |
||
78 |
subsection {* Code serialization setup *} |
|
79 |
||
20453
855f07fabd76
final syntax for some Isar code generator keywords
haftmann
parents:
20400
diff
changeset
|
80 |
code_type "typ" and "term" |
855f07fabd76
final syntax for some Isar code generator keywords
haftmann
parents:
20400
diff
changeset
|
81 |
(SML target_atom "Term.typ" and target_atom "Term.term") |
20400 | 82 |
|
20453
855f07fabd76
final syntax for some Isar code generator keywords
haftmann
parents:
20400
diff
changeset
|
83 |
code_const Type and TFix |
855f07fabd76
final syntax for some Isar code generator keywords
haftmann
parents:
20400
diff
changeset
|
84 |
and Const and App and Fix |
855f07fabd76
final syntax for some Isar code generator keywords
haftmann
parents:
20400
diff
changeset
|
85 |
(SML "Term.Type (_, _)" and "Term.TFree (_, _)" |
855f07fabd76
final syntax for some Isar code generator keywords
haftmann
parents:
20400
diff
changeset
|
86 |
and "Term.Const (_, _)" and "Term.$ (_, _)" and "Term.Free (_, _)") |
20400 | 87 |
|
88 |
end |