-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path170411.tex
196 lines (181 loc) · 6.01 KB
/
170411.tex
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
% TODO
% If $\vd \Gamma \ok$, $\Gamma \vdp M \of \sigma$, $\Gamma \vd \Fst{M} \gg c$ then
% $\Gamma \vdp M \of \singleton{c \of \sigma}
% However, this isn't actually true until we add in the extensionality rules.
% This the REASON that we even have them.
Note that the last rule in the previous section is wrong.
We instead add the appropriate extensionality rules to replace it.
\begin{mathpar}
\inferrule{
\Gamma \vdp M \of \sigma \splitsto \sd{c}{e} \\
\Gamma \vd \Fst{M} \gg c
}{
\Gamma \vdp M \of \singleton{c \of \sigma} \splitsto \sd{c}{e}
}
\end{mathpar}
To prove type correctness for the above, we want to show: \\
$c \of k'$ \\
$e \of \subst{c}{\alpha}{\tau'}$ \\
The first is trivially true, since $k' = \singleton{c \of k}$, since
singleton is commutative. \\
For the second, lemma: \\
If $\Gamma \vd \sigma \of \sig$, $\Gamma \vd c \of k$,
$\sigma \splitsto \bind{\alpha \of k}{\tau}$, \\
then, $\Gamma, \alpha \of k' \vd \tau \equiv \tau' \of \type$,
$\Gamma \vd \subst{c}{\alpha}{\tau} \equiv \subst{c}{\alpha}{\tau} \of \type$
% CODING NOTE: we basically ignore all of the above
% Phase Splitting rule (algorithmic) that WE use is:
\begin{mathpar}
\inferrule{
\alpha/s \of \sigma \in \Gamma
}{
\Gamma \vdp s \implies \singleton{\alpha \of \sigma} \splitsto \sd{\alpha}{s}
}
\end{mathpar}
% TODO
\begin{mathpar}
\inferrule{
\Gamma \vdp M \of \sigma \splitsto \sd{c}{e} \\
\Gamma \vd \sigma \le \sigma'a \splitsto f
}{
\Gamma \vdp M \of \sigma' \splitsto \sd{c}{\ap{f[c]}{e}}
}
\end{mathpar}
New judgement to construct the above: \\
If $\Gamma \vd \sigma \le \sigma' \splitsto f$,
$\sigma \splitsto \bind{\alpha \of k}{\tau}$,
$\sigma' \splitsto \bind{\alpha \of k'}{\tau'}$,
then %TODO
\begin{mathpar}
\inferrule{
\Gamma \vd \sigma \equiv \sigma' \of \sig \\
\sigma \bind{\splitsto \alpha \of k}{\tau}
}{
\Gamma \vd \sigma \le \sigma' \splitsto \Lam{\alpha \of k}{\lambda\bind{x \of \tau}{x}}
}
\inferrule{
\Gamma \vd \sigma_1 \le \sigma_2 \splitsto f_1 \\
\Gamma \vd \sigma_2 \le \sigma_3 \splitsto f_1 \\
\sigma_1 \splitsto \bind{\alpha \of k_1}{\tau_1}
}{
\Gamma \vd \sigma_1 \le \sigma_3 \splitsto
\Lam{\alpha \of k_1}{\lam{x \of \tau_1}{\ap{f_2[\alpha]}{\ap{f_1[\alpha]}{x}}}}
}
\inferrule{
\Gamma \vd k \le k'
}{
\Gamma \vd \satom{k} \le \satom{k'} \splitsto
\Lam{\alpha \of k}{\lam{x \of \unit}{x}}
}
\inferrule{
\Gamma \vd \sigma_1' \le \sigma_1 \splitsto f_1 \\
\Gamma, \alpha \of \Fst{\sigma_1'} \vd \sigma_2 \le \sigma_2' \splitsto f_2 \\
\Gamma, \alpha \of \Fst{\sigma_1} \vd \sigma_2 \of \sig
}{
\Gamma \vd \Pig{\alpha \of \sigma_1}{\sigma_2} \le
\Pig{\alpha \of \sigma_1'}{\sigma_2'} \splitsto \\
\Lam{\_ \of 1}{
\lam{f \of
\forall\bind{\alpha \of k_1}{
\subst{\alpha}{\alpha_1}{\tau_1} \arrow
\exists\bind{\alpha_2 \of k_2}{\tau_2}
}
}{
\Lam{\alpha \of k_1'}{
\lam{x \of \subst{\alpha}{\alpha_1}{\tau_1'}}{
\unpackbind{\alpha_2}{y}{
\ap{f[\alpha]}{\ap{f_1[\alpha]}{x}}
}{
\packbind{\alpha_2}{\ap{f_2[\alpha_2]}{y}}{
\exists\bind{\alpha_2 \of k_2'}{\tau_2'}
}
}
}
}
}
}
}
\inferrule{
\Gamma \vd \sigma_1' \le \sigma_1 \splitsto f_1 \\
\Gamma, \alpha \of \Fst{\sigma_1'} \vd \sigma_2 \le \sigma_2' \splitsto f_2 \\
\Gamma, \alpha \of \Fst{\sigma_1} \vd \sigma_2 \of \sig
}{
\Gamma \vd \Pia{\alpha \of \sigma_1}{\sigma_2} \le
\Pia{\alpha \of \sigma_1'}{\sigma_2'} \splitsto \\
\Lam{\beta\of \Pi\bind{\alpha \of k_1}{k_2}}{
\lam{f \of
\forall\bind{\alpha \of k_1}{
\subst{\alpha}{\alpha_1}{\tau_1} \arrow
\subst{\ap{\beta}{\alpha}}{\alpha_2}{\tau_2}
}
}{
\Lam{\alpha \of k_1'}{
\lam{x \of \subst{\alpha}{\alpha_1}{\tau_1'}}{
\ap{f_2[\ap{\beta}{\alpha}]}{\ap{f[\alpha]}{\ap{f_1[\alpha]}{x}}}
}
}
}
}
}
\inferrule{
\Gamma \vd \sigma_1 \le \sigma_1' \splitsto f_1 \\
\Gamma, \alpha \of \Fst{\sigma_1} \vd \sigma_2 \le \sigma_2' \splitsto f_2 \\
\Gamma, \alpha \of \Fst{\sigma_1} \vd \sigma_2 \of \sig
}{
\Gamma \vd \Sigma\bind{\alpha \of \sigma_1}{\sigma_2} \le
\Sigma\bind{\alpha \of \sigma_1'}{\sigma_2'} \splitsto \\
\Lam{
\beta \of \sigma\bind{\alpha \of k_1}{k_2}
}{
\lam{x \of \subst{\pi_1 \beta}{\alpha_1}{\tau_1} \times
\subst{\pi_1 \beta, \pi_2 \beta}{\alpha_1, \alpha_2}{\tau_2}}{
\pair{
\ap{f_1[\pi_1 \beta]}{\pi_0^\ast x},
\subst{\pi_1 \beta}{\alpha}{
\ap{f_2[\pi_2 \beta]}{\pi_1^\ast x}
}
}
}
}
}
\end{mathpar}
% TODO
\vspace{1cm}
CODING NOTE: the right thing is above (see pi-gen), BUT, the below
will work since the autograder does not check for it.
\begin{mathpar}
\inferrule{
\Gamma \vdp M \of \sigma \splitsto \sd{c}{e} \\
\Gamma \vd \sigma \le \sigma' \\
\sigma \splitsto \bind{\alpha \of k}{\tau} \\
\sigma' \splitsto \bind{\alpha \of k'}{\tau'} \\
\Gamma, \alpha \of k \vd \tau \equiv \tau' \\
}{
\Gamma \vdp M \of \sigma' \splitsto \sd{c}{e}
}
\end{mathpar}
\subsection{TODO}
Now let's look at sealing
\begin{mathpar}
\inferrule{
\Gamma \vdi M \checking \sigma
}{
\Gamma \vdi \seal{M}{\sigma} \synthesis \sigma \splitsto e
}
\inferrule{
\Gamma \vdi M \synthesis \sigma' \splitsto e \\
\Gamma \vd \sigma' \triangleq \sigma
}{
\Gamma \vdi M \checking \sigma \splitsto e
}
\end{mathpar}
Coding Note (the SIMPLE way):
\begin{lstlisting}
translatePure : context -> module -> con * con * term * sg
translateImpure : context -> module -> term * sg
\end{lstlisting}
The better way:
\begin{lstlisting}
datatype result = con * con * term * sg | term * sg
translate : context -> module -> result
\end{lstlisting}