author | urbanc |
Sat, 07 Jan 2006 13:50:38 +0100 | |
changeset 18611 | 687c9bffbca1 |
parent 17781 | 32bb237158a5 |
child 19796 | d86e7b1fc472 |
permissions | -rw-r--r-- |
17456 | 1 |
(* Title: CCL/Term.thy |
0 | 2 |
ID: $Id$ |
1474 | 3 |
Author: Martin Coen |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
*) |
|
6 |
||
17456 | 7 |
header {* Definitions of usual program constructs in CCL *} |
8 |
||
9 |
theory Term |
|
10 |
imports CCL |
|
11 |
begin |
|
0 | 12 |
|
13 |
consts |
|
14 |
||
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
15 |
one :: "i" |
0 | 16 |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
17 |
if :: "[i,i,i]=>i" ("(3if _/ then _/ else _)" [0,0,60] 60) |
0 | 18 |
|
17456 | 19 |
inl :: "i=>i" |
20 |
inr :: "i=>i" |
|
21 |
when :: "[i,i=>i,i=>i]=>i" |
|
0 | 22 |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
23 |
split :: "[i,[i,i]=>i]=>i" |
17456 | 24 |
fst :: "i=>i" |
25 |
snd :: "i=>i" |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
26 |
thd :: "i=>i" |
0 | 27 |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
28 |
zero :: "i" |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
29 |
succ :: "i=>i" |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
30 |
ncase :: "[i,i,i=>i]=>i" |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
31 |
nrec :: "[i,i,[i,i]=>i]=>i" |
0 | 32 |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
33 |
nil :: "i" ("([])") |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
34 |
"$" :: "[i,i]=>i" (infixr 80) |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
35 |
lcase :: "[i,i,[i,i]=>i]=>i" |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
36 |
lrec :: "[i,i,[i,i,i]=>i]=>i" |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
37 |
|
17456 | 38 |
"let" :: "[i,i=>i]=>i" |
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
39 |
letrec :: "[[i,i=>i]=>i,(i=>i)=>i]=>i" |
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
40 |
letrec2 :: "[[i,i,i=>i=>i]=>i,(i=>i=>i)=>i]=>i" |
17456 | 41 |
letrec3 :: "[[i,i,i,i=>i=>i=>i]=>i,(i=>i=>i=>i)=>i]=>i" |
0 | 42 |
|
14765 | 43 |
syntax |
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
44 |
"@let" :: "[idt,i,i]=>i" ("(3let _ be _/ in _)" |
1474 | 45 |
[0,0,60] 60) |
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
46 |
|
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
47 |
"@letrec" :: "[idt,idt,i,i]=>i" ("(3letrec _ _ be _/ in _)" |
1474 | 48 |
[0,0,0,60] 60) |
0 | 49 |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
50 |
"@letrec2" :: "[idt,idt,idt,i,i]=>i" ("(3letrec _ _ _ be _/ in _)" |
1474 | 51 |
[0,0,0,0,60] 60) |
0 | 52 |
|
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
53 |
"@letrec3" :: "[idt,idt,idt,idt,i,i]=>i" ("(3letrec _ _ _ _ be _/ in _)" |
1474 | 54 |
[0,0,0,0,0,60] 60) |
998
91d09e262799
Gave tighter priorities to if, napply and the let-forms to
lcp
parents:
610
diff
changeset
|
55 |
|
17456 | 56 |
ML {* |
0 | 57 |
(** Quantifier translations: variable binding **) |
58 |
||
17781 | 59 |
(* FIXME does not handle "_idtdummy" *) |
2709 | 60 |
(* FIXME should use Syntax.mark_bound(T), Syntax.variant_abs' *) |
61 |
||
0 | 62 |
fun let_tr [Free(id,T),a,b] = Const("let",dummyT) $ a $ absfree(id,T,b); |
63 |
fun let_tr' [a,Abs(id,T,b)] = |
|
64 |
let val (id',b') = variant_abs(id,T,b) |
|
65 |
in Const("@let",dummyT) $ Free(id',T) $ a $ b' end; |
|
66 |
||
17456 | 67 |
fun letrec_tr [Free(f,S),Free(x,T),a,b] = |
0 | 68 |
Const("letrec",dummyT) $ absfree(x,T,absfree(f,S,a)) $ absfree(f,S,b); |
17456 | 69 |
fun letrec2_tr [Free(f,S),Free(x,T),Free(y,U),a,b] = |
0 | 70 |
Const("letrec2",dummyT) $ absfree(x,T,absfree(y,U,absfree(f,S,a))) $ absfree(f,S,b); |
17456 | 71 |
fun letrec3_tr [Free(f,S),Free(x,T),Free(y,U),Free(z,V),a,b] = |
0 | 72 |
Const("letrec3",dummyT) $ absfree(x,T,absfree(y,U,absfree(z,U,absfree(f,S,a)))) $ absfree(f,S,b); |
73 |
||
74 |
fun letrec_tr' [Abs(x,T,Abs(f,S,a)),Abs(ff,SS,b)] = |
|
75 |
let val (f',b') = variant_abs(ff,SS,b) |
|
76 |
val (_,a'') = variant_abs(f,S,a) |
|
77 |
val (x',a') = variant_abs(x,T,a'') |
|
78 |
in Const("@letrec",dummyT) $ Free(f',SS) $ Free(x',T) $ a' $ b' end; |
|
79 |
fun letrec2_tr' [Abs(x,T,Abs(y,U,Abs(f,S,a))),Abs(ff,SS,b)] = |
|
80 |
let val (f',b') = variant_abs(ff,SS,b) |
|
81 |
val ( _,a1) = variant_abs(f,S,a) |
|
82 |
val (y',a2) = variant_abs(y,U,a1) |
|
83 |
val (x',a') = variant_abs(x,T,a2) |
|
84 |
in Const("@letrec2",dummyT) $ Free(f',SS) $ Free(x',T) $ Free(y',U) $ a' $ b' |
|
85 |
end; |
|
86 |
fun letrec3_tr' [Abs(x,T,Abs(y,U,Abs(z,V,Abs(f,S,a)))),Abs(ff,SS,b)] = |
|
87 |
let val (f',b') = variant_abs(ff,SS,b) |
|
88 |
val ( _,a1) = variant_abs(f,S,a) |
|
89 |
val (z',a2) = variant_abs(z,V,a1) |
|
90 |
val (y',a3) = variant_abs(y,U,a2) |
|
91 |
val (x',a') = variant_abs(x,T,a3) |
|
92 |
in Const("@letrec3",dummyT) $ Free(f',SS) $ Free(x',T) $ Free(y',U) $ Free(z',V) $ a' $ b' |
|
93 |
end; |
|
94 |
||
17456 | 95 |
*} |
96 |
||
97 |
parse_translation {* |
|
98 |
[("@let", let_tr), |
|
99 |
("@letrec", letrec_tr), |
|
100 |
("@letrec2", letrec2_tr), |
|
101 |
("@letrec3", letrec3_tr)] *} |
|
102 |
||
103 |
print_translation {* |
|
104 |
[("let", let_tr'), |
|
105 |
("letrec", letrec_tr'), |
|
106 |
("letrec2", letrec2_tr'), |
|
107 |
("letrec3", letrec3_tr')] *} |
|
108 |
||
109 |
consts |
|
110 |
napply :: "[i=>i,i,i]=>i" ("(_ ^ _ ` _)" [56,56,56] 56) |
|
111 |
||
112 |
axioms |
|
113 |
||
114 |
one_def: "one == true" |
|
115 |
if_def: "if b then t else u == case(b,t,u,% x y. bot,%v. bot)" |
|
116 |
inl_def: "inl(a) == <true,a>" |
|
117 |
inr_def: "inr(b) == <false,b>" |
|
118 |
when_def: "when(t,f,g) == split(t,%b x. if b then f(x) else g(x))" |
|
119 |
split_def: "split(t,f) == case(t,bot,bot,f,%u. bot)" |
|
120 |
fst_def: "fst(t) == split(t,%x y. x)" |
|
121 |
snd_def: "snd(t) == split(t,%x y. y)" |
|
122 |
thd_def: "thd(t) == split(t,%x p. split(p,%y z. z))" |
|
123 |
zero_def: "zero == inl(one)" |
|
124 |
succ_def: "succ(n) == inr(n)" |
|
125 |
ncase_def: "ncase(n,b,c) == when(n,%x. b,%y. c(y))" |
|
126 |
nrec_def: " nrec(n,b,c) == letrec g x be ncase(x,b,%y. c(y,g(y))) in g(n)" |
|
127 |
nil_def: "[] == inl(one)" |
|
128 |
cons_def: "h$t == inr(<h,t>)" |
|
129 |
lcase_def: "lcase(l,b,c) == when(l,%x. b,%y. split(y,c))" |
|
130 |
lrec_def: "lrec(l,b,c) == letrec g x be lcase(x,b,%h t. c(h,t,g(t))) in g(l)" |
|
131 |
||
132 |
let_def: "let x be t in f(x) == case(t,f(true),f(false),%x y. f(<x,y>),%u. f(lam x. u(x)))" |
|
133 |
letrec_def: |
|
134 |
"letrec g x be h(x,g) in b(g) == b(%x. fix(%f. lam x. h(x,%y. f`y))`x)" |
|
135 |
||
136 |
letrec2_def: "letrec g x y be h(x,y,g) in f(g)== |
|
137 |
letrec g' p be split(p,%x y. h(x,y,%u v. g'(<u,v>))) |
|
138 |
in f(%x y. g'(<x,y>))" |
|
139 |
||
140 |
letrec3_def: "letrec g x y z be h(x,y,z,g) in f(g) == |
|
141 |
letrec g' p be split(p,%x xs. split(xs,%y z. h(x,y,z,%u v w. g'(<u,<v,w>>)))) |
|
142 |
in f(%x y z. g'(<x,<y,z>>))" |
|
143 |
||
144 |
napply_def: "f ^n` a == nrec(n,a,%x g. f(g))" |
|
145 |
||
146 |
ML {* use_legacy_bindings (the_context ()) *} |
|
147 |
||
148 |
end |