-
Notifications
You must be signed in to change notification settings - Fork 0
/
plt-redex.rkt
122 lines (100 loc) · 2.01 KB
/
plt-redex.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#lang racket
(require redex)
(define-language L
(e (e e)
(λ (x t) e)
x
(amb e ...)
number
(+ e ...)
(if0 e e e)
(fix e))
(t (→ t t) num)
(x variable-not-otherwise-mentioned))
; First example
(redex-match
L
e
(term (λ (x) x)))
; Second example
(redex-match
L
e
(term ((λ (x num) (amb x 1))
(+ 1 2))))
; Third example
(redex-match
L
(e_1 e_2)
(term ((λ (x num) (amb x 1))
(+ 1 2))))
; Fourth example
(redex-match
L
(e_1 ... e_2 e_3 ...)
(term ((+ 1 2)
(+ 3 4)
(+ 5 6))))
; Exercise 1
(redex-match
L
((λ (_ _) e) _)
(term ((λ (x num) (+ x 1))
17)))
; Exercise 2
(redex-match
L
(→ num t)
(term (→ num (→ num num))))
; Exercise 3
(redex-match
L
(_ ... e_1 e_2 _ ...)
(term (1 2 3 4)))
; Exercise 4
(redex-match
L
(_ ..._1 e_left _ ..._2 _ _ ..._2 e_right _ ..._1)
(term (1 2 3 4 5)))
; Typing
(define-extended-language L+Γ L
[Γ · (x : t Γ)])
(define-judgment-form
L+Γ
#:mode (types I I O)
#:contract (types Γ e t)
[(types Γ e_1 (→ t_2 t_3))
(types Γ e_2 t_2)
-------------------------
(types Γ (e_1 e_2) t_3)]
[(types (x : t_1 Γ) e t_2)
-----------------------------------
(types Γ (λ (x t_1) e) (→ t_1 t_2))]
[(types Γ e (→ (→ t_1 t_2) (→ t_1 t_2)))
---------------------------------------
(types Γ (fix e) (→ t_1 t_2))]
[---------------------
(types (x : t Γ) x t)]
[(types Γ x_1 t_1)
(side-condition (different x_1 x_2))
------------------------------------
(types (x_2 : t_2 Γ) x_1 t_1)]
[(types Γ e num) ...
-----------------------
(types Γ (+ e ...) num)]
[--------------------
(types Γ number num)]
[(types Γ e_1 num)
(types Γ e_2 t)
(types Γ e_3 t)
-----------------------------
(types Γ (if0 e_1 e_2 e_3) t)]
[(types Γ e num) ...
--------------------------
(types Γ (amb e ...) num)])
(judgment-holds
(types ·
((λ (x num) (amb x 1))
(+ 1 2))
t)
t)