-
Notifications
You must be signed in to change notification settings - Fork 0
/
assistant-calculus.tex
460 lines (411 loc) · 14.6 KB
/
assistant-calculus.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
\section{Assistant Calculus}\label{sec:assistant-calculus}
blah blah blah types
{\fontspec{Symbola}\symbol{"1F4CE}}
{\fontspec{Symbola}\symbol{"1F4CE}}
\paperclip
$\paperclip$
TODOs:
\begin{itemize}
\item \sout{get cursor icons from hazelnut paper }
\item \sout{get right arrow for bidi}
\item \sout{basic zipper cases}
\item remaining zipper cases? do i need to actually include mirror cases?
\item \sout{var + varapp}
\item \sout{NOTE: we basically need a construct expression action for varapp}
\item \sout{proj}
\item \sout{base case for hole}
\item \sout{base cases for non-empty holes, incld:}
\item \sout{delete + act for general hexps}
\item \sout{simple wrap for exprs incld. non-empty-holes}
\item complex (n-ary) wraps
\item iterated wraps? with cutoffs? (:jean-shorts-emoji)
\item \sout{are there non-empty-hole suggests distinct from arbitrary expr suggests?} don't think so
\item \sout{for all: change type to type consistency}
\item \sout{for all: add numerical subscripts to types where missing}
\item \sout{fig 4: make it consistency not equal}
\item \sout{fig 5: change proj judgement to analysis}
\item \sout{fig 4: change varapp proj to have x in gamma, not gamma comma x}
\item \sout{consider matched product, matched arrow to suggest for unknown types}
\item above: not sure i want matched arrow type in fig 5? feels weirder to suggest an unknown typed var for fn than value...
\item rankings:
\item priviledge more specific types
\item read contextual modal types
\item \sout{replace constructs with construct-expressions}
\item AppProj needs a better treatment for selection (should be first non-empty hole)... chain a separate action?
\item implementation: implement ENTER vs TAB
\item add keyboard shortcuts for swap etc
\item proj1 and proj2: make tau in product another underscore
\item intro rule for type=hole
\item fig 4 var and approj case: type consistency not premise: put in
\item read: polarity: noam zalburger. bob harper blog post
\item what does it mean to synthesize 'action a': sensibility theorem:
\item well-typed in synthetic case, checked against tau in analytic case
\item $\suggest{A}{B}$
\item $\suggestp{A}{B}$
\item $\paperclip$
\item NEW
\item synthetic pos: everything
\item sensibility: all actions result in well-typed states
\item constructiblity of complete terms: with move to next hole
\item scorers: symbol + subscript for judgement (num holes judgement)
\end{itemize}
\newcommand{\singleton}[1]{\{ #1 \}}
\newcommand{\singleaction}[1]{\singleton{\mathtt{#1}}}
\newcommand{\varapparrow}[0]{\rightsquigarrow}
\newcommand{\varappjudge}[4]{#1 \vdash #2 \varapparrow #3 \Leftarrow #4}
\newcommand{\projjudge}[4]{#1 \vdash #2 \twoheadrightarrow #3 \Leftarrow #4}
\newpage
\begin{figure}[t]
$\arraycolsep=4pt
\begin{array}{lllllll}
\mathsf{HTyp} & \tau & ::= &
\tunit ~\vert~
\tsum{\tau}{\tau} ~\vert~
\tprod{\tau}{\tau} ~\vert~
\tarr{\tau}{\tau} ~\vert~
\tehole\\
\mathsf{HExp} & \hexp & ::= &
() ~\vert~
L~e ~\vert~
R~e ~\vert~
({\hexp},{\hexp}) ~\vert~
x ~\vert~
{\hlam{x}{\hexp}} ~\vert~
{\hexp}(\hexp) ~\vert~
\hehole ~\vert~
\hhole{\hexp}
\end{array}$
\caption{Syntax of H-types and H-expressions. Metavariable $x$ ranges over variables.}
\label{fig:hexp-syntax}
\end{figure}
\begin{figure}
\centering
\fbox{$\suggest
{\hsyn{\hGamma}{\zexp}{\tau}}
{\bigalpha}$}~~\text{$\hexp$ synthesizes $\tau$, suggesting actions $\bigalpha$}
\\
\fbox{$\suggest
{\hana{\hGamma}{\zexp}{\tau}}
{\bigalpha}$}~~\text{$\hexp$ analyzes against $\tau$, suggesting actions $\bigalpha$} \\
\caption{Suggestion Judgement Forms}
\label{fig:suggest_judge}
\end{figure}
\begin{figure}
\begin{mathpar}
\centering
\inferrule[]{
\suggest
{\hana{\hGamma}{\zexp}{\tau_1}}
{\bigalpha}
}{
\suggest
{\hana{\hGamma}{L~\zexp}{\tsum{\tau_1}{\tau_2}}}
{\bigalpha}
}
\\
\inferrule[]{
\suggest
{\hana{\hGamma}{\zexp}{\tau_2}}
{\bigalpha}
}{
\suggest
{\hana{\hGamma}{R~\zexp}{\tsum{\tau_1}{\tau_2}}}
{\bigalpha}
}
\\
\inferrule[]{
\hana{\hGamma}{\hexp_1}{\tau_2} \\
\suggest
{\hana{\hGamma}{\zexp_2}{\tau_1}}
{\bigalpha}
}{
\suggest
{\hana{\hGamma}{(\hexp_1, \zexp_2)}{\tprod{\tau_1}{\tau_2}}}
{\bigalpha}
}
\\
\inferrule[]{
\suggest
{\hana{\hGamma}{\zexp_1}{\tau_1}}
{\bigalpha}\\
\hana{\hGamma}{\hexp_2}{\tau_2}
}{
\suggest
{\hana{\hGamma}{(\zexp_1, \hexp_2)}{\tprod{\tau_1}{\tau_2}}}
{\bigalpha}
}
\\
\inferrule[]{
\suggest
{\hsyn{\hGamma}{\zexp_1}{\tau_1}}
{\bigalpha} \\
\arrmatch{\tau_1}{\tarr{\tau_2}{\tau}} \\
\hana{\hGamma}{\hexp_2}{\tau_2}
}{
\suggest
{\hana{\hGamma}{\dap{\zexp_1}{\hexp_2}}{\tau}}
{\bigalpha}
}
\\
\inferrule[]{
\hsyn{\hGamma}{\hexp_1}{\tau_1}
\\
\arrmatch{\tau_1}{\tarr{\tau_2}{\tau}} \\
\suggest
{\hana{\hGamma}{\zexp_2}{\tau_2}}
{\bigalpha}
}{
\suggest
{\hana{\hGamma}{\dap{\hexp_1}{\zexp_2}}{\tau}}
{\bigalpha}
}
\\
\inferrule[]{
\arrmatch{\tau}{\tarr{\tau_1}{\tau_2}} \\
\suggest
{\hana{\hGamma, x: \tau_1}{\zexp}{\tau_2}}
{\bigalpha}
}{
\suggest
{\hana{\hGamma}{\hlam{x}{\zexp}}{\tau}}
{\bigalpha}
}
\\
\inferrule[DoesThisWork]{
\suggest
{\hana{\hGamma}{\zexp}{\tau}}
{\bigalpha}
}{
\suggest
{\hana{\hGamma}{\hhole{\zexp}}{\tau}}
{\bigalpha}
}
\\
\end{mathpar}
\caption{Analytic Suggestion Zipper Cases}
\label{fig:suggests_zipper}
\end{figure}
\begin{figure}
\begin{mathpar}
\inferrule[Suggest Expr Syn]{
\suggest
{\hana{\hGamma}{\zexp}{\tehole{}}}
{\bigalpha_{}}
}{
\suggest
{\hsyn{\hGamma}{\zexp}{\_}}
{\bigalpha_{}}
}
\end{mathpar}
\caption{Synthetic Case}
\end{figure}
\begin{figure}
\begin{mathpar}
\inferrule[Suggest Hole Analytic]{
\suggestStar{\mathsf{Intros}(\tau)}{\bigalpha_{intros}} \\
\suggestStar{\mathsf{Elims}(\Gamma, \tau)}{\bigalpha_{elims}}
}{
\suggest
{\hana{\hGamma}{\zwsel{\hehole{}}}{\tau}}
{\bigalpha_{intros} \cup \bigalpha_{elims}}
}
\\
\inferrule[Suggest Expr Analytic]{
\suggestStar{\mathsf{Wraps}(\hexp, \tau)}{\bigalpha_{wraps}} \\
\suggestStar{\mathsf{Replaces}(\Gamma, \tau)}{\bigalpha_{replaces}}
}{
\suggest
{\hana{\hGamma}{\zwsel{\hexp}}{\tau}}
{\bigalpha_{wraps} \cup \bigalpha_{replaces}}
}
\\
\inferrule[Replacement]{
\suggest
{\hana{\hGamma}{\zwsel{\hehole{}}}{\tau}}
{\bigalpha}
}
{
\suggestStar
{\mathsf{Replaces}(\Gamma, \tau)}
{\{ \mathtt{del} \;;\; \alpha \;|\; \alpha \in \bigalpha\}}
}
\\
\inferrule[Wrapping (simple)]{
\hsyn{\hGamma}{\hexp}{\tau_e} \\
\tconsistent{\tau_e}{\tau'}
}
{
\suggestStar
{\mathsf{Wraps}(\hexp, \tau)}
{\{ \construct{\dap{f}{\zwsel{\hexp}}} \;|\; f : \tarr{\tau'}{\tau} \in \Gamma\}}
}
\end{mathpar}
\caption{Analytic base cases}
\label{fig:suggests}
\end{figure}
\begin{figure}
\begin{mathpar}
\inferrule[IntrosTriv]
{ }
{\suggestStar
{\mathsf{Intros}(\tunit)}
{\singleaction{\construct{\zwsel{()}}}}}
\inferrule[IntrosProd]
{ }
{\suggestStar
{\mathsf{Intros}(\tprod{\tau_1}{\tau_2})}
{\singleaction{\construct{\hpair{\zwsel{\hehole{}}}{\hehole{}}}}}}
\inferrule[IntrosArrow]
{ }
{\suggestStar
{\mathsf{Intros}(\tarr{\tau_1}{\tau_2})}
{\singleaction{\construct{\hlam{x}{\zwsel{\hehole{}}}}}}}
\inferrule[IntrosSum]
{ }
{\suggestStar
{\mathsf{Intros}(\tsum{\tau_1}{\tau_2})}
{\{{\construct{\hinL{\zwsel{\hehole{}}}}},
{\construct{\hinR{\zwsel{\hehole{}}}}}} \}}
\inferrule[IntrosHole]
{
\suggestStar{\mathsf{Intros}(1)}{\bigalpha_{1}} \\
\suggestStar{\mathsf{Intros}(\tprod{\tehole}{\tehole})}{\bigalpha_{\tprod{}{}}} \\
\suggestStar{\mathsf{Intros}(\tsum{\tehole}{\tehole})}{\bigalpha_{\tsum{}{}}} \\
\suggestStar{\mathsf{Intros}(\tarr{\tehole}{\tehole})}{\bigalpha_{\tarr{}{}}} \\
}
{\suggestStar
{\mathsf{Intros}(\tehole{})}
{\bigalpha_{1} \cup {\bigalpha_{\tprod{}{}} \cup \bigalpha_{\tsum{}{}} \cup \bigalpha_{\tarr{}{}}}}}
\end{mathpar}
\caption{Introduction suggestions}
\label{fig:suggest_intros}
\end{figure}
\begin{figure}
\begin{mathpar}
\inferrule[Suggest Elims]{
\suggestStar{\mathsf{ElimCase}}{\bigalpha_{case}} \\
\suggestStar{\mathsf{Var}(\Gamma, \tau)}{\bigalpha_{var}} \\
\suggestStar{\mathsf{AppProj}(\Gamma, \tau)}{\bigalpha_{approj}} \\
}{
\suggestStar
{\mathsf{Elims}(\Gamma, \tau)}
{\bigalpha_{case} \cup \bigalpha_{var} \cup \bigalpha_{approj}}
}
\inferrule[ElimCase]
{ }
{\suggestStar
{\mathsf{ElimCase}}
{\singleaction{\construct{\hcase{\zwsel{\hehole{}}}{x}{\hehole{}}{y}{\hehole{}}}}}}
\inferrule[Var]
{\tconsistent{\tau}{\tau'}}
{\suggestStar
{\mathsf{Var}(\Gamma, \tau)}
{\{\mathtt{\construct{\zwsel{x}}} \;|\; x : \tau' \in \Gamma\}}}
\inferrule[AppProj]
{\tconsistent{\tau}{\tau'}}
{\suggestStar
{\mathsf{AppProj}(\Gamma, \tau)}
{\{\mathtt{\construct{\zwsel{e}}}
\;|\;
x : \tau' \in \Gamma \; \wedge \; \varappjudge{\Gamma}{x}{e}{\tau}\}}}
\end{mathpar}
\caption{Elimination suggestions}
\label{fig:suggest_elims}
\end{figure}
\begin{figure}
\judgbox
{\varappjudge{\Gamma}{\hexp}{\hexp'}{\tau}}
{ \\ $\hexp$, applied to 0 or more holes, \\ and projected 0 or more times, \\
yields an expr analyzing to $\tau$}
\begin{mathpar}
\inferrule[AppProjBase]
{\hana{\Gamma}{\hexp}{\tau}}
{\varappjudge{\Gamma}{e}{e}{\tau}}
% output type is tau'' != hole
%
\inferrule[App]
{
\hsyn{\Gamma}{\hexp}{\tau'} \\
\arrmatch{\tau'}{\tarr{\_}{\_}} \\
\varappjudge{\Gamma}{\dap{\hexp}{\hehole{}}}{\hexp'}{\tau}
}
{\varappjudge{\Gamma}{\hexp}{\hexp'}{\tau}}
\inferrule[Proj1]
{
\hsyn{\Gamma}{\hexp}{\tau'} \\
\prodmatch{\tau'}{\tprod{\tau}{\_}} \\
\varappjudge{\Gamma}{\pi_1 \hexp}{\hexp'}{\tau}
}
{\varappjudge{\Gamma}{e}{e'}{\tau}}
\inferrule[Proj2]
{
\hsyn{\Gamma}{\hexp}{\tau'} \\
\prodmatch{\tau'}{\tprod{\_}{\tau}} \\
\varappjudge{\Gamma}{\pi_2 \hexp}{\hexp'}{\tau}
}
{\varappjudge{\Gamma}{e}{e'}{\tau}}
\end{mathpar}
\caption{Supporting elimination judgments}
\label{fig:support_elims}
\end{figure}
\begin{figure}
\begin{mathpar}
\centering
\inferrule[Errors Triv]{ }
{ \errorCount{()}{0} }
\inferrule[Errors Var]{ }
{ \errorCount{x}{0} }
\inferrule[Errors EmptyHole]{ }
{ \errorCount{\hehole{}}{0} }
\inferrule[Errors NonEmptyHole]
{ \errorCount{\hexp}{n} }
{ \errorCount{\hhole{\hexp}{}}{n+1} }
\inferrule[Errors Lambda]
{ \errorCount{\hexp}{n} }
{ \errorCount{\hlam{x}{\hexp}}{n+1} }
\inferrule[Errors Pair]{
\errorCount{\hexp_1}{n_1} \\
\errorCount{\hexp_2}{n_2} \\
n_1 + n_2 = n
}{ \errorCount{(\hexp_1,\hexp_2)}{n} }
\inferrule[Errors Ap]{
\errorCount{\hexp_1}{n_1} \\
\errorCount{\hexp_2}{n_2} \\
n_1 + n_2 = n
}{ \errorCount{\dap{\hexp_1}{\hexp_2}}{n} }
\end{mathpar}
\caption{Count hole rules}
\end{figure}
\begin{figure}
\begin{itemize}
\item T3 (Suggestion sensibility theorem):\\
For all $\Gamma, \zexp, \tau, a \in \bigalpha$
where $\suggest
{\hana{\hGamma}{\zexp}{\tau}}
{\bigalpha}$ \\
there exists $\zexp', \tau'$ \\
such that $\numErrors{\removeSel{\hexp}} \leq \numErrors{\removeSel{\hexp'}}$
and $\performAna{\hGamma}{\zexp}{\tau}{\alpha}{\zexp'}$ \\
\\
\item T0 (Suggestion generalizes typing Ana):\\
For all $\Gamma, \zexp, \tau, \bigalpha$ \\
where $\suggest
{\hana{\hGamma}{\zexp}{\tau}}
{\bigalpha}$ \\
we have $\hana{\hGamma}{\removeSel{\zexp}}{\tau}$\\
\\
\item T1 (Existence and uniqueness of suggestions Ana):\\
For all $\Gamma, \zexp, \tau$
such that $\hana{\hGamma}{\removeSel{\zexp}}{\tau}$, \\
there exists a unique $\bigalpha$ such that
$\suggest
{\hana{\hGamma}{\zexp}{\tau}}
{\bigalpha}$\\
\\
\item T2 (lemma for T1):\\
For all $\tau$ there exists a unique $\bigalpha$ such that \\
$\suggestStar {\mathsf{Intros}(\tau)} {\bigalpha}$\\
\\
\end{itemize}
\caption{Theorems & Lemmas}
\end{figure}