-
Notifications
You must be signed in to change notification settings - Fork 4
/
slides4.html
332 lines (311 loc) · 44 KB
/
slides4.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="author" content="Jesper Cockx">
<meta name="dcterms.date" content="2019-09-03">
<title>Correct-by-construction programming in Agda</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//css/reveal.css">
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//css/theme/black.css" id="theme">
<link rel="stylesheet" href="white.css"/>
<link rel="stylesheet" href="Agda.css"/>
<link rel="stylesheet" href="patchTheme.css"/>
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//css/print/pdf.css' : 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section id="title-slide">
<h1 class="title">Correct-by-construction programming in Agda</h1>
<p class="subtitle">Lecture 4: (Non-)termination</p>
<p class="author">Jesper Cockx</p>
<p class="date">3 September 2019</p>
</section>
<section id="section" class="slide level2">
<h2></h2>
<p>"I’ll save the world…</p>
<p>tomorrow."</p>
<p>– unknown</p>
</section>
<section><section id="totality-checking" class="title-slide slide level1"><h1>Totality checking</h1></section><section id="partial-functions-in-type-theory" class="slide level2">
<h2>Partial functions in type theory</h2>
<!--
<pre class="Agda"><a id="352" class="Keyword">open</a> <a id="357" class="Keyword">import</a> <a id="364" href="Library.html" class="Module">Library</a>
</pre>-->
<p>What happens if we have a partial function in Agda?</p>
<ul>
<li>Theory would become inconsistent!</li>
</ul>
<pre class="unchecked"><code>absurd : ⊥
absurd = absurd</code></pre>
<ul>
<li>Typechecker would crash or loop!</li>
</ul>
<pre class="unchecked"><code>f : ℕ → ℕ
f zero = 42
test : Vec ℕ (f 1)
test = []</code></pre>
<p>⇒ Partial functions must be ruled out!</p>
</section><section id="checking-totality" class="slide level2">
<h2>Checking totality</h2>
<ol type="1">
<li><strong>Completeness</strong> of pattern matching</li>
<li><strong>Structural recursion</strong> of recursive functions</li>
<li><strong>Strict positivity</strong> of inductive datatypes</li>
<li><strong>Consistency</strong> of universe levels</li>
</ol>
<p>2-4 together ensure normalization of well-typed terms</p>
</section><section id="primitive-recursion" class="slide level2">
<h2>Primitive recursion</h2>
<pre class="Agda"><a id="plus"></a><a id="942" href="slides4.html#942" class="Function">plus</a> <a id="947" class="Symbol">:</a> <a id="949" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="951" class="Symbol">→</a> <a id="953" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="955" class="Symbol">→</a> <a id="957" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a>
<a id="959" href="slides4.html#942" class="Function">plus</a> <a id="964" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="972" href="slides4.html#972" class="Bound">m</a> <a id="974" class="Symbol">=</a> <a id="976" href="slides4.html#972" class="Bound">m</a>
<a id="978" href="slides4.html#942" class="Function">plus</a> <a id="983" class="Symbol">(</a><a id="984" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="988" href="slides4.html#988" class="Bound">n</a><a id="989" class="Symbol">)</a> <a id="991" href="slides4.html#991" class="Bound">m</a> <a id="993" class="Symbol">=</a> <a id="995" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="999" class="Symbol">(</a><a id="1000" href="slides4.html#942" class="Function">plus</a> <a id="1005" href="slides4.html#988" class="Bound">n</a> <a id="1007" href="slides4.html#991" class="Bound">m</a><a id="1008" class="Symbol">)</a>
<a id="natEq"></a><a id="1011" href="slides4.html#1011" class="Function">natEq</a> <a id="1017" class="Symbol">:</a> <a id="1019" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="1021" class="Symbol">→</a> <a id="1023" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="1025" class="Symbol">→</a> <a id="1027" href="Agda.Builtin.Bool.html#135" class="Datatype">Bool</a>
<a id="1032" href="slides4.html#1011" class="Function">natEq</a> <a id="1038" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1046" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1054" class="Symbol">=</a> <a id="1056" href="Agda.Builtin.Bool.html#160" class="InductiveConstructor">true</a>
<a id="1061" href="slides4.html#1011" class="Function">natEq</a> <a id="1067" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1075" class="Symbol">(</a><a id="1076" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1080" href="slides4.html#1080" class="Bound">m</a><a id="1081" class="Symbol">)</a> <a id="1083" class="Symbol">=</a> <a id="1085" href="Agda.Builtin.Bool.html#154" class="InductiveConstructor">false</a>
<a id="1091" href="slides4.html#1011" class="Function">natEq</a> <a id="1097" class="Symbol">(</a><a id="1098" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1102" href="slides4.html#1102" class="Bound">n</a><a id="1103" class="Symbol">)</a> <a id="1105" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1113" class="Symbol">=</a> <a id="1115" href="Agda.Builtin.Bool.html#154" class="InductiveConstructor">false</a>
<a id="1121" href="slides4.html#1011" class="Function">natEq</a> <a id="1127" class="Symbol">(</a><a id="1128" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1132" href="slides4.html#1132" class="Bound">n</a><a id="1133" class="Symbol">)</a> <a id="1135" class="Symbol">(</a><a id="1136" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1140" href="slides4.html#1140" class="Bound">m</a><a id="1141" class="Symbol">)</a> <a id="1143" class="Symbol">=</a> <a id="1145" href="slides4.html#1011" class="Function">natEq</a> <a id="1151" href="slides4.html#1132" class="Bound">n</a> <a id="1153" href="slides4.html#1140" class="Bound">m</a>
</pre>
</section><section id="structural-recursion" class="slide level2">
<h2>Structural recursion</h2>
<pre class="Agda"><a id="fib"></a><a id="1189" href="slides4.html#1189" class="Function">fib</a> <a id="1193" class="Symbol">:</a> <a id="1195" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="1197" class="Symbol">→</a> <a id="1199" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a>
<a id="1201" href="slides4.html#1189" class="Function">fib</a> <a id="1205" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1219" class="Symbol">=</a> <a id="1221" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a>
<a id="1226" href="slides4.html#1189" class="Function">fib</a> <a id="1230" class="Symbol">(</a><a id="1231" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1235" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a><a id="1239" class="Symbol">)</a> <a id="1244" class="Symbol">=</a> <a id="1246" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1250" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a>
<a id="1255" href="slides4.html#1189" class="Function">fib</a> <a id="1259" class="Symbol">(</a><a id="1260" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1264" class="Symbol">(</a><a id="1265" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1269" href="slides4.html#1269" class="Bound">n</a><a id="1270" class="Symbol">))</a> <a id="1273" class="Symbol">=</a> <a id="1275" href="slides4.html#942" class="Function">plus</a> <a id="1280" class="Symbol">(</a><a id="1281" href="slides4.html#1189" class="Function">fib</a> <a id="1285" href="slides4.html#1269" class="Bound">n</a><a id="1286" class="Symbol">)</a> <a id="1288" class="Symbol">(</a><a id="1289" href="slides4.html#1189" class="Function">fib</a> <a id="1293" class="Symbol">(</a><a id="1294" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1298" href="slides4.html#1269" class="Bound">n</a><a id="1299" class="Symbol">))</a>
</pre>
<pre class="Agda"><a id="ack"></a><a id="1311" href="slides4.html#1311" class="Function">ack</a> <a id="1315" class="Symbol">:</a> <a id="1317" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="1319" class="Symbol">→</a> <a id="1321" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="1323" class="Symbol">→</a> <a id="1325" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a>
<a id="1327" href="slides4.html#1311" class="Function">ack</a> <a id="1331" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1339" href="slides4.html#1339" class="Bound">m</a> <a id="1347" class="Symbol">=</a> <a id="1349" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1353" href="slides4.html#1339" class="Bound">m</a>
<a id="1355" href="slides4.html#1311" class="Function">ack</a> <a id="1359" class="Symbol">(</a><a id="1360" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1364" href="slides4.html#1364" class="Bound">n</a><a id="1365" class="Symbol">)</a> <a id="1367" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="1375" class="Symbol">=</a> <a id="1377" href="slides4.html#1311" class="Function">ack</a> <a id="1381" href="slides4.html#1364" class="Bound">n</a> <a id="1383" class="Symbol">(</a><a id="1384" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1388" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a><a id="1392" class="Symbol">)</a>
<a id="1394" href="slides4.html#1311" class="Function">ack</a> <a id="1398" class="Symbol">(</a><a id="1399" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1403" href="slides4.html#1403" class="Bound">n</a><a id="1404" class="Symbol">)</a> <a id="1406" class="Symbol">(</a><a id="1407" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1411" href="slides4.html#1411" class="Bound">m</a><a id="1412" class="Symbol">)</a> <a id="1414" class="Symbol">=</a> <a id="1416" href="slides4.html#1311" class="Function">ack</a> <a id="1420" href="slides4.html#1403" class="Bound">n</a> <a id="1422" class="Symbol">(</a><a id="1423" href="slides4.html#1311" class="Function">ack</a> <a id="1427" class="Symbol">(</a><a id="1428" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="1432" href="slides4.html#1403" class="Bound">n</a><a id="1433" class="Symbol">)</a> <a id="1435" href="slides4.html#1411" class="Bound">m</a><a id="1436" class="Symbol">)</a>
</pre>
</section></section>
<section><section id="coinduction" class="title-slide slide level1"><h1>Coinduction</h1></section><section id="a-frequently-asked-question" class="slide level2">
<h2>A frequently asked question</h2>
<p>“If all functions in Agda are total, doesn’t that mean Agda is not Turing-complete?”</p>
<div class="fragment">
<p><em>Answer</em>: <strong>NO!</strong> Agda just forces you to be <em>honest</em> about when a function is non-terminating.</p>
</div>
</section><section id="coinduction-in-agda" class="slide level2">
<h2>Coinduction in Agda</h2>
<p>A <strong>coinductive type</strong> = a type with possibly infinitely deep values.</p>
<!--
<pre class="Agda"><a id="1788" class="Keyword">module</a> <a id="Coinduction"></a><a id="1795" href="slides4.html#1795" class="Module">Coinduction</a> <a id="1807" class="Keyword">where</a>
<a id="1815" class="Keyword">module</a> <a id="GuardedStream"></a><a id="1822" href="slides4.html#1822" class="Module">GuardedStream</a> <a id="1836" class="Keyword">where</a>
</pre>-->
<pre class="Agda"> <a id="1863" class="Keyword">record</a> <a id="Coinduction.GuardedStream.Stream"></a><a id="1870" href="slides4.html#1870" class="Record">Stream</a> <a id="1877" class="Symbol">(</a><a id="1878" href="slides4.html#1878" class="Bound">A</a> <a id="1880" class="Symbol">:</a> <a id="1882" class="PrimitiveType">Set</a><a id="1885" class="Symbol">)</a> <a id="1887" class="Symbol">:</a> <a id="1889" class="PrimitiveType">Set</a> <a id="1893" class="Keyword">where</a>
<a id="1905" class="Keyword">coinductive</a>
<a id="1923" class="Keyword">field</a>
<a id="Coinduction.GuardedStream.Stream.head"></a><a id="1937" href="slides4.html#1937" class="Field">head</a> <a id="1942" class="Symbol">:</a> <a id="1944" href="slides4.html#1878" class="Bound">A</a>
<a id="Coinduction.GuardedStream.Stream.tail"></a><a id="1954" href="slides4.html#1954" class="Field">tail</a> <a id="1959" class="Symbol">:</a> <a id="1961" href="slides4.html#1870" class="Record">Stream</a> <a id="1968" href="slides4.html#1878" class="Bound">A</a>
<a id="1974" class="Keyword">open</a> <a id="1979" href="slides4.html#1870" class="Module">Stream</a>
<a id="Coinduction.GuardedStream.repeat"></a><a id="1991" href="slides4.html#1991" class="Function">repeat</a> <a id="1998" class="Symbol">:</a> <a id="2000" class="Symbol">{</a><a id="2001" href="slides4.html#2001" class="Bound">A</a> <a id="2003" class="Symbol">:</a> <a id="2005" class="PrimitiveType">Set</a><a id="2008" class="Symbol">}</a> <a id="2010" class="Symbol">→</a> <a id="2012" href="slides4.html#2001" class="Bound">A</a> <a id="2014" class="Symbol">→</a> <a id="2016" href="slides4.html#1870" class="Record">Stream</a> <a id="2023" href="slides4.html#2001" class="Bound">A</a>
<a id="2029" href="slides4.html#1937" class="Field">head</a> <a id="2034" class="Symbol">(</a><a id="2035" href="slides4.html#1991" class="Function">repeat</a> <a id="2042" href="slides4.html#2042" class="Bound">x</a><a id="2043" class="Symbol">)</a> <a id="2045" class="Symbol">=</a> <a id="2047" href="slides4.html#2042" class="Bound">x</a>
<a id="2053" href="slides4.html#1954" class="Field">tail</a> <a id="2058" class="Symbol">(</a><a id="2059" href="slides4.html#1991" class="Function">repeat</a> <a id="2066" href="slides4.html#2066" class="Bound">x</a><a id="2067" class="Symbol">)</a> <a id="2069" class="Symbol">=</a> <a id="2071" href="slides4.html#1991" class="Function">repeat</a> <a id="2078" href="slides4.html#2066" class="Bound">x</a>
</pre>
</section><section id="mixing-induction-and-coinduction-12" class="slide level2">
<h2>Mixing induction and coinduction (1/2)</h2>
<pre class="Agda"> <a id="2136" class="Keyword">mutual</a>
<a id="2147" class="Keyword">record</a> <a id="Coinduction.Coℕ′"></a><a id="2154" href="slides4.html#2154" class="Record">Coℕ′</a> <a id="2159" class="Symbol">:</a> <a id="2161" class="PrimitiveType">Set</a> <a id="2165" class="Keyword">where</a>
<a id="2177" class="Keyword">coinductive</a>
<a id="2195" class="Keyword">field</a>
<a id="Coinduction.Coℕ′.force"></a><a id="2209" href="slides4.html#2209" class="Field">force</a> <a id="2215" class="Symbol">:</a> <a id="2217" href="slides4.html#2231" class="Datatype">Coℕ</a>
<a id="2226" class="Keyword">data</a> <a id="Coinduction.Coℕ"></a><a id="2231" href="slides4.html#2231" class="Datatype">Coℕ</a> <a id="2235" class="Symbol">:</a> <a id="2237" class="PrimitiveType">Set</a> <a id="2241" class="Keyword">where</a>
<a id="Coinduction.Coℕ.zero"></a><a id="2253" href="slides4.html#2253" class="InductiveConstructor">zero</a> <a id="2258" class="Symbol">:</a> <a id="2260" href="slides4.html#2231" class="Datatype">Coℕ</a>
<a id="Coinduction.Coℕ.suc"></a><a id="2270" href="slides4.html#2270" class="InductiveConstructor">suc</a> <a id="2275" class="Symbol">:</a> <a id="2277" href="slides4.html#2154" class="Record">Coℕ′</a> <a id="2282" class="Symbol">→</a> <a id="2284" href="slides4.html#2231" class="Datatype">Coℕ</a>
<a id="2290" class="Keyword">open</a> <a id="2295" href="slides4.html#2154" class="Module">Coℕ′</a> <a id="2300" class="Keyword">public</a>
</pre>
</section><section id="mixing-induction-and-coinduction-22" class="slide level2">
<h2>Mixing induction and coinduction (2/2)</h2>
<pre class="Agda"> <a id="Coinduction.fromℕ"></a><a id="2361" href="slides4.html#2361" class="Function">fromℕ</a> <a id="2367" class="Symbol">:</a> <a id="2369" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="2371" class="Symbol">→</a> <a id="2373" href="slides4.html#2231" class="Datatype">Coℕ</a>
<a id="Coinduction.fromℕ′"></a><a id="2379" href="slides4.html#2379" class="Function">fromℕ′</a> <a id="2386" class="Symbol">:</a> <a id="2388" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="2390" class="Symbol">→</a> <a id="2392" href="slides4.html#2154" class="Record">Coℕ′</a>
<a id="2400" href="slides4.html#2361" class="Function">fromℕ</a> <a id="2406" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="2411" class="Symbol">=</a> <a id="2413" href="slides4.html#2253" class="InductiveConstructor">zero</a>
<a id="2420" href="slides4.html#2361" class="Function">fromℕ</a> <a id="2426" class="Symbol">(</a><a id="2427" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="2431" href="slides4.html#2431" class="Bound">x</a><a id="2432" class="Symbol">)</a> <a id="2434" class="Symbol">=</a> <a id="2436" href="slides4.html#2270" class="InductiveConstructor">suc</a> <a id="2440" class="Symbol">(</a><a id="2441" href="slides4.html#2379" class="Function">fromℕ′</a> <a id="2448" href="slides4.html#2431" class="Bound">x</a><a id="2449" class="Symbol">)</a>
<a id="2454" href="slides4.html#2379" class="Function">fromℕ′</a> <a id="2461" href="slides4.html#2461" class="Bound">x</a> <a id="2463" class="Symbol">.</a><a id="2464" href="slides4.html#2209" class="Field">force</a> <a id="2470" class="Symbol">=</a> <a id="2472" href="slides4.html#2361" class="Function">fromℕ</a> <a id="2478" href="slides4.html#2461" class="Bound">x</a>
<a id="Coinduction.infty"></a><a id="2483" href="slides4.html#2483" class="Function">infty</a> <a id="2490" class="Symbol">:</a> <a id="2492" href="slides4.html#2231" class="Datatype">Coℕ</a>
<a id="Coinduction.infty′"></a><a id="2498" href="slides4.html#2498" class="Function">infty′</a> <a id="2505" class="Symbol">:</a> <a id="2507" href="slides4.html#2154" class="Record">Coℕ′</a>
<a id="2515" href="slides4.html#2483" class="Function">infty</a> <a id="2521" class="Symbol">=</a> <a id="2523" href="slides4.html#2270" class="InductiveConstructor">suc</a> <a id="2527" href="slides4.html#2498" class="Function">infty′</a>
<a id="2536" href="slides4.html#2498" class="Function">infty′</a> <a id="2543" class="Symbol">.</a><a id="2544" href="slides4.html#2209" class="Field">force</a> <a id="2550" class="Symbol">=</a> <a id="2552" href="slides4.html#2483" class="Function">infty</a>
</pre>
</section><section id="dealing-with-infinite-computations" class="slide level2">
<h2>Dealing with infinite computations</h2>
<p>Remember: all Agda functions must be <strong>total</strong></p>
<p>One way to work around this is by adding ‘fuel’:</p>
<!--
<pre class="Agda"> <a id="2711" class="Keyword">postulate</a>
<a id="Coinduction.⋯"></a><a id="2725" href="slides4.html#2725" class="Postulate">⋯</a> <a id="2727" class="Symbol">:</a> <a id="2729" class="Symbol">{</a><a id="2730" href="slides4.html#2730" class="Bound">A</a> <a id="2732" class="Symbol">:</a> <a id="2734" class="PrimitiveType">Set</a><a id="2737" class="Symbol">}</a> <a id="2739" class="Symbol">→</a> <a id="2741" href="slides4.html#2730" class="Bound">A</a>
<a id="Coinduction.Term"></a><a id="2747" href="slides4.html#2747" class="Postulate">Term</a> <a id="Coinduction.Val"></a><a id="2752" href="slides4.html#2752" class="Postulate">Val</a> <a id="2756" class="Symbol">:</a> <a id="2758" class="PrimitiveType">Set</a>
</pre>-->
<pre class="Agda"> <a id="Coinduction.step"></a><a id="2777" href="slides4.html#2777" class="Function">step</a> <a id="2782" class="Symbol">:</a> <a id="2784" href="slides4.html#2747" class="Postulate">Term</a> <a id="2789" class="Symbol">→</a> <a id="2791" href="slides4.html#2747" class="Postulate">Term</a> <a id="2796" href="Data.Sum.Base.html#617" class="Datatype Operator">⊎</a> <a id="2798" href="slides4.html#2752" class="Postulate">Val</a>
<a id="2804" href="slides4.html#2777" class="Function">step</a> <a id="2809" class="Symbol">=</a> <a id="2811" href="slides4.html#2725" class="Postulate">⋯</a>
<a id="Coinduction.eval"></a><a id="2816" href="slides4.html#2816" class="Function">eval</a> <a id="2821" class="Symbol">:</a> <a id="2823" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="2825" class="Symbol">→</a> <a id="2827" href="slides4.html#2747" class="Postulate">Term</a> <a id="2832" class="Symbol">→</a> <a id="2834" href="Data.Maybe.Base.html#800" class="Datatype">Maybe</a> <a id="2840" href="slides4.html#2752" class="Postulate">Val</a>
<a id="2846" href="slides4.html#2816" class="Function">eval</a> <a id="2851" class="Symbol">(</a><a id="2852" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="2856" href="slides4.html#2856" class="Bound">n</a><a id="2857" class="Symbol">)</a> <a id="2859" href="slides4.html#2859" class="Bound">t</a> <a id="2861" class="Symbol">=</a> <a id="2863" href="Function.Core.html#3716" class="Function Operator">case</a> <a id="2868" class="Symbol">(</a><a id="2869" href="slides4.html#2777" class="Function">step</a> <a id="2874" href="slides4.html#2859" class="Bound">t</a><a id="2875" class="Symbol">)</a> <a id="2877" href="Function.Core.html#3716" class="Function Operator">of</a> <a id="2880" class="Symbol">λ</a> <a id="2882" class="Keyword">where</a>
<a id="2892" class="Symbol">(</a><a id="2893" href="Data.Sum.Base.html#667" class="InductiveConstructor">inj₁</a> <a id="2898" href="slides4.html#2898" class="Bound">t'</a><a id="2900" class="Symbol">)</a> <a id="2902" class="Symbol">→</a> <a id="2904" href="slides4.html#2816" class="Function">eval</a> <a id="2909" href="slides4.html#2856" class="Bound">n</a> <a id="2911" href="slides4.html#2859" class="Bound">t</a>
<a id="2917" class="Symbol">(</a><a id="2918" href="Data.Sum.Base.html#692" class="InductiveConstructor">inj₂</a> <a id="2923" href="slides4.html#2923" class="Bound">v</a><a id="2924" class="Symbol">)</a> <a id="2927" class="Symbol">→</a> <a id="2929" href="Data.Maybe.Base.html#834" class="InductiveConstructor">just</a> <a id="2934" href="slides4.html#2923" class="Bound">v</a>
<a id="2938" href="slides4.html#2816" class="Function">eval</a> <a id="2943" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="2948" href="slides4.html#2948" class="Bound">t</a> <a id="2950" class="Symbol">=</a> <a id="2952" href="Data.Maybe.Base.html#864" class="InductiveConstructor">nothing</a>
</pre>
<p>Can we do better?</p>
</section><section id="going-carbon-free-with-the-delay-monad" class="slide level2">
<h2>Going carbon-free with the <code>Delay</code> monad</h2>
<p>A value of type <code>Delay A</code> is</p>
<ul>
<li>either a value of type <code>A</code> produced <strong>now</strong></li>
<li>or a computation of type <code>Delay A</code> producing a value <strong>later</strong></li>
</ul>
<p>The <code>Delay</code> monad captures the effect of <em>non-termination</em></p>
</section><section id="the-delay-monad-definition" class="slide level2">
<h2>The Delay monad: definition</h2>
<pre class="Agda"> <a id="3274" class="Keyword">mutual</a>
<a id="3285" class="Keyword">record</a> <a id="Coinduction.Delay"></a><a id="3292" href="slides4.html#3292" class="Record">Delay</a> <a id="3298" class="Symbol">(</a><a id="3299" href="slides4.html#3299" class="Bound">A</a> <a id="3301" class="Symbol">:</a> <a id="3303" class="PrimitiveType">Set</a><a id="3306" class="Symbol">)</a> <a id="3308" class="Symbol">:</a> <a id="3310" class="PrimitiveType">Set</a> <a id="3314" class="Keyword">where</a>
<a id="3326" class="Keyword">coinductive</a>
<a id="3344" class="Keyword">field</a> <a id="Coinduction.Delay.force"></a><a id="3350" href="slides4.html#3350" class="Field">force</a> <a id="3356" class="Symbol">:</a> <a id="3358" href="slides4.html#3377" class="Datatype">Delay'</a> <a id="3365" href="slides4.html#3299" class="Bound">A</a>
<a id="3372" class="Keyword">data</a> <a id="Coinduction.Delay'"></a><a id="3377" href="slides4.html#3377" class="Datatype">Delay'</a> <a id="3384" class="Symbol">(</a><a id="3385" href="slides4.html#3385" class="Bound">A</a> <a id="3387" class="Symbol">:</a> <a id="3389" class="PrimitiveType">Set</a><a id="3392" class="Symbol">)</a> <a id="3394" class="Symbol">:</a> <a id="3396" class="PrimitiveType">Set</a> <a id="3400" class="Keyword">where</a>
<a id="Coinduction.Delay'.now"></a><a id="3412" href="slides4.html#3412" class="InductiveConstructor">now</a> <a id="3418" class="Symbol">:</a> <a id="3420" href="slides4.html#3385" class="Bound">A</a> <a id="3428" class="Symbol">→</a> <a id="3430" href="slides4.html#3377" class="Datatype">Delay'</a> <a id="3437" href="slides4.html#3385" class="Bound">A</a>
<a id="Coinduction.Delay'.later"></a><a id="3445" href="slides4.html#3445" class="InductiveConstructor">later</a> <a id="3451" class="Symbol">:</a> <a id="3453" href="slides4.html#3292" class="Record">Delay</a> <a id="3459" href="slides4.html#3385" class="Bound">A</a> <a id="3461" class="Symbol">→</a> <a id="3463" href="slides4.html#3377" class="Datatype">Delay'</a> <a id="3470" href="slides4.html#3385" class="Bound">A</a>
<a id="3475" class="Keyword">open</a> <a id="3480" href="slides4.html#3292" class="Module">Delay</a> <a id="3486" class="Keyword">public</a>
<a id="Coinduction.never"></a><a id="3496" href="slides4.html#3496" class="Function">never</a> <a id="3502" class="Symbol">:</a> <a id="3504" class="Symbol">{</a><a id="3505" href="slides4.html#3505" class="Bound">A</a> <a id="3507" class="Symbol">:</a> <a id="3509" class="PrimitiveType">Set</a><a id="3512" class="Symbol">}</a> <a id="3514" class="Symbol">→</a> <a id="3516" href="slides4.html#3292" class="Record">Delay</a> <a id="3522" href="slides4.html#3505" class="Bound">A</a>
<a id="3526" href="slides4.html#3350" class="Field">force</a> <a id="3532" href="slides4.html#3496" class="Function">never</a> <a id="3538" class="Symbol">=</a> <a id="3540" href="slides4.html#3445" class="InductiveConstructor">later</a> <a id="3546" href="slides4.html#3496" class="Function">never</a>
</pre>
</section><section id="unrolling-a-delayed-value" class="slide level2">
<h2>Unrolling a <code>Delay</code>ed value</h2>
<pre class="Agda"> <a id="Coinduction.unroll"></a><a id="3595" href="slides4.html#3595" class="Function">unroll</a> <a id="3602" class="Symbol">:</a> <a id="3604" class="Symbol">{</a><a id="3605" href="slides4.html#3605" class="Bound">A</a> <a id="3607" class="Symbol">:</a> <a id="3609" class="PrimitiveType">Set</a><a id="3612" class="Symbol">}</a> <a id="3614" class="Symbol">→</a> <a id="3616" href="Agda.Builtin.Nat.html#165" class="Datatype">ℕ</a> <a id="3618" class="Symbol">→</a> <a id="3620" href="slides4.html#3292" class="Record">Delay</a> <a id="3626" href="slides4.html#3605" class="Bound">A</a> <a id="3628" class="Symbol">→</a> <a id="3630" href="slides4.html#3605" class="Bound">A</a> <a id="3632" href="Data.Sum.Base.html#617" class="Datatype Operator">⊎</a> <a id="3634" href="slides4.html#3292" class="Record">Delay</a> <a id="3640" href="slides4.html#3605" class="Bound">A</a>
<a id="3644" href="slides4.html#3595" class="Function">unroll</a> <a id="3651" href="Agda.Builtin.Nat.html#183" class="InductiveConstructor">zero</a> <a id="3659" href="slides4.html#3659" class="Bound">x</a> <a id="3661" class="Symbol">=</a> <a id="3663" href="Data.Sum.Base.html#692" class="InductiveConstructor">inj₂</a> <a id="3668" href="slides4.html#3659" class="Bound">x</a>
<a id="3672" href="slides4.html#3595" class="Function">unroll</a> <a id="3679" class="Symbol">(</a><a id="3680" href="Agda.Builtin.Nat.html#196" class="InductiveConstructor">suc</a> <a id="3684" href="slides4.html#3684" class="Bound">n</a><a id="3685" class="Symbol">)</a> <a id="3687" href="slides4.html#3687" class="Bound">x</a> <a id="3689" class="Symbol">=</a> <a id="3691" href="Function.Core.html#3716" class="Function Operator">case</a> <a id="3696" class="Symbol">(</a><a id="3697" href="slides4.html#3350" class="Field">force</a> <a id="3703" href="slides4.html#3687" class="Bound">x</a><a id="3704" class="Symbol">)</a> <a id="3706" href="Function.Core.html#3716" class="Function Operator">of</a> <a id="3709" class="Symbol">λ</a> <a id="3711" class="Keyword">where</a>
<a id="3721" class="Symbol">(</a><a id="3722" href="slides4.html#3412" class="InductiveConstructor">now</a> <a id="3726" href="slides4.html#3726" class="Bound">v</a> <a id="3729" class="Symbol">)</a> <a id="3731" class="Symbol">→</a> <a id="3733" href="Data.Sum.Base.html#667" class="InductiveConstructor">inj₁</a> <a id="3738" href="slides4.html#3726" class="Bound">v</a>
<a id="3744" class="Symbol">(</a><a id="3745" href="slides4.html#3445" class="InductiveConstructor">later</a> <a id="3751" href="slides4.html#3751" class="Bound">d</a><a id="3752" class="Symbol">)</a> <a id="3754" class="Symbol">→</a> <a id="3756" href="slides4.html#3595" class="Function">unroll</a> <a id="3763" href="slides4.html#3684" class="Bound">n</a> <a id="3765" href="slides4.html#3751" class="Bound">d</a>
</pre>
</section></section>
<section><section id="sized-types" class="title-slide slide level1"><h1>Sized types</h1></section><section id="using-sizes-to-prove-termination" class="slide level2">
<h2>Using sizes to prove termination</h2>
<p>Totality requirement: coinductive definitions should be <strong>productive</strong>: computing each observation should be terminating.</p>
<p>To ensure this, Agda checks that corecursive calls are <strong>guarded by constructors</strong>, but this is often quite limiting.</p>
<p>A more flexible and modular approach is to use <strong>sized types</strong>.</p>
</section><section id="the-type-size" class="slide level2">
<h2>The type <code>Size</code></h2>
<p><code>Size</code> ≃ abstract version of the natural numbers extended with <code>∞</code></p>
<p>For each <code>i : Size</code>, we have a type <code>Size< i</code> of sizes <strong>smaller than <code>i</code></strong>.</p>
<p><strong>Note</strong>: pattern matching on <code>Size</code> is not allowed!</p>
</section><section id="the-sized-delay-monad" class="slide level2">
<h2>The sized delay monad</h2>
<!--
<pre class="Agda"><a id="4390" class="Keyword">module</a> <a id="SizedTypes"></a><a id="4397" href="slides4.html#4397" class="Module">SizedTypes</a> <a id="4408" class="Keyword">where</a>
<a id="4416" class="Keyword">open</a> <a id="4421" class="Keyword">import</a> <a id="4428" href="Size.html" class="Module">Size</a>
</pre>-->
<pre class="Agda"> <a id="4452" class="Keyword">mutual</a>
<a id="4463" class="Keyword">record</a> <a id="SizedTypes.Delay"></a><a id="4470" href="slides4.html#4470" class="Record">Delay</a> <a id="4476" class="Symbol">(</a><a id="4477" href="slides4.html#4477" class="Bound">i</a> <a id="4479" class="Symbol">:</a> <a id="4481" href="Agda.Builtin.Size.html#179" class="Postulate">Size</a><a id="4485" class="Symbol">)</a> <a id="4487" class="Symbol">(</a><a id="4488" href="slides4.html#4488" class="Bound">A</a> <a id="4490" class="Symbol">:</a> <a id="4492" class="PrimitiveType">Set</a><a id="4495" class="Symbol">)</a> <a id="4497" class="Symbol">:</a> <a id="4499" class="PrimitiveType">Set</a> <a id="4503" class="Keyword">where</a>
<a id="4515" class="Keyword">coinductive</a>
<a id="4533" class="Keyword">constructor</a> <a id="SizedTypes.Delay.delay"></a><a id="4545" href="slides4.html#4545" class="CoinductiveConstructor">delay</a>
<a id="4557" class="Keyword">field</a>
<a id="SizedTypes.Delay.force"></a><a id="4571" href="slides4.html#4571" class="Field">force</a> <a id="4577" class="Symbol">:</a> <a id="4579" class="Symbol">{</a><a id="4580" href="slides4.html#4580" class="Bound">j</a> <a id="4582" class="Symbol">:</a> <a id="4584" href="Agda.Builtin.Size.html#211" class="Postulate Operator">Size<</a> <a id="4590" href="slides4.html#4477" class="Bound">i</a><a id="4591" class="Symbol">}</a> <a id="4593" class="Symbol">→</a> <a id="4595" href="slides4.html#4616" class="Datatype">Delay'</a> <a id="4602" href="slides4.html#4580" class="Bound">j</a> <a id="4604" href="slides4.html#4488" class="Bound">A</a>
<a id="4611" class="Keyword">data</a> <a id="SizedTypes.Delay'"></a><a id="4616" href="slides4.html#4616" class="Datatype">Delay'</a> <a id="4623" class="Symbol">(</a><a id="4624" href="slides4.html#4624" class="Bound">i</a> <a id="4626" class="Symbol">:</a> <a id="4628" href="Agda.Builtin.Size.html#179" class="Postulate">Size</a><a id="4632" class="Symbol">)</a> <a id="4634" class="Symbol">(</a><a id="4635" href="slides4.html#4635" class="Bound">A</a> <a id="4637" class="Symbol">:</a> <a id="4639" class="PrimitiveType">Set</a><a id="4642" class="Symbol">)</a> <a id="4644" class="Symbol">:</a> <a id="4646" class="PrimitiveType">Set</a> <a id="4650" class="Keyword">where</a>
<a id="SizedTypes.Delay'.return'"></a><a id="4662" href="slides4.html#4662" class="InductiveConstructor">return'</a> <a id="4670" class="Symbol">:</a> <a id="4672" href="slides4.html#4635" class="Bound">A</a> <a id="4682" class="Symbol">→</a> <a id="4684" href="slides4.html#4616" class="Datatype">Delay'</a> <a id="4691" href="slides4.html#4624" class="Bound">i</a> <a id="4693" href="slides4.html#4635" class="Bound">A</a>
<a id="SizedTypes.Delay'.later'"></a><a id="4701" href="slides4.html#4701" class="InductiveConstructor">later'</a> <a id="4709" class="Symbol">:</a> <a id="4711" href="slides4.html#4470" class="Record">Delay</a> <a id="4717" href="slides4.html#4624" class="Bound">i</a> <a id="4719" href="slides4.html#4635" class="Bound">A</a> <a id="4721" class="Symbol">→</a> <a id="4723" href="slides4.html#4616" class="Datatype">Delay'</a> <a id="4730" href="slides4.html#4624" class="Bound">i</a> <a id="4732" href="slides4.html#4635" class="Bound">A</a>
</pre>
<p><code>i</code> ≃ how many more steps are we allowed to observe.</p>
<p><code>Delay ∞ A</code> is the type of computations that can take <em>any</em> number of steps.</p>
</section><section id="interpreting-well-typed-while-programs" class="slide level2">
<h2>Interpreting well-typed WHILE programs</h2>
<p>WHILE statements can have two effects:</p>
<ul>
<li>Modify the environment ⇒ <code>State</code> monad</li>
<li>Go into a loop ⇒ <code>Delay</code> monad</li>
</ul>
<p>We combine both effects in the <code>Exec</code> monad.</p>
</section><section id="the-exec-monad" class="slide level2">
<h2>The <code>Exec</code> monad</h2>
<!--
<pre class="Agda"> <a id="5122" class="Keyword">open</a> <a id="5127" class="Keyword">import</a> <a id="5134" href="Library.html" class="Module">Library</a>
<a id="5144" class="Keyword">postulate</a>
<a id="SizedTypes.⋯"></a><a id="5158" href="slides4.html#5158" class="Postulate">⋯</a> <a id="5160" class="Symbol">:</a> <a id="5162" class="Symbol">{</a><a id="5163" href="slides4.html#5163" class="Bound">A</a> <a id="5165" class="Symbol">:</a> <a id="5167" class="PrimitiveType">Set</a><a id="5170" class="Symbol">}</a> <a id="5172" class="Symbol">→</a> <a id="5174" href="slides4.html#5163" class="Bound">A</a>
<a id="SizedTypes.Cxt"></a><a id="5180" href="slides4.html#5180" class="Postulate">Cxt</a> <a id="5184" class="Symbol">:</a> <a id="5186" class="PrimitiveType">Set</a>
<a id="SizedTypes.Stm"></a><a id="5194" href="slides4.html#5194" class="Postulate">Stm</a> <a id="5198" class="Symbol">:</a> <a id="5200" href="slides4.html#5180" class="Postulate">Cxt</a> <a id="5204" class="Symbol">→</a> <a id="5206" class="PrimitiveType">Set</a>
<a id="SizedTypes.Env"></a><a id="5214" href="slides4.html#5214" class="Postulate">Env</a> <a id="5218" class="Symbol">:</a> <a id="5220" href="slides4.html#5180" class="Postulate">Cxt</a> <a id="5224" class="Symbol">→</a> <a id="5226" class="PrimitiveType">Set</a>
<a id="SizedTypes.Program"></a><a id="5234" href="slides4.html#5234" class="Postulate">Program</a> <a id="5242" class="Symbol">:</a> <a id="5244" class="PrimitiveType">Set</a>
</pre>-->
<pre class="Agda"> <a id="5267" class="Keyword">record</a> <a id="SizedTypes.Exec"></a><a id="5274" href="slides4.html#5274" class="Record">Exec</a> <a id="5279" class="Symbol">{</a><a id="5280" href="slides4.html#5280" class="Bound">Γ</a> <a id="5282" class="Symbol">:</a> <a id="5284" href="slides4.html#5180" class="Postulate">Cxt</a><a id="5287" class="Symbol">}</a> <a id="5289" class="Symbol">(</a><a id="5290" href="slides4.html#5290" class="Bound">i</a> <a id="5292" class="Symbol">:</a> <a id="5294" href="Agda.Builtin.Size.html#179" class="Postulate">Size</a><a id="5298" class="Symbol">)</a> <a id="5300" class="Symbol">(</a><a id="5301" href="slides4.html#5301" class="Bound">A</a> <a id="5303" class="Symbol">:</a> <a id="5305" class="PrimitiveType">Set</a><a id="5308" class="Symbol">)</a> <a id="5310" class="Symbol">:</a> <a id="5312" class="PrimitiveType">Set</a> <a id="5316" class="Keyword">where</a>
<a id="5326" class="Keyword">field</a>
<a id="SizedTypes.Exec.runExec"></a><a id="5338" href="slides4.html#5338" class="Field">runExec</a> <a id="5346" class="Symbol">:</a> <a id="5348" class="Symbol">(</a><a id="5349" href="slides4.html#5349" class="Bound">ρ</a> <a id="5351" class="Symbol">:</a> <a id="5353" href="slides4.html#5214" class="Postulate">Env</a> <a id="5357" href="slides4.html#5280" class="Bound">Γ</a><a id="5358" class="Symbol">)</a> <a id="5360" class="Symbol">→</a> <a id="5362" href="slides4.html#4470" class="Record">Delay</a> <a id="5368" href="slides4.html#5290" class="Bound">i</a> <a id="5370" class="Symbol">(</a><a id="5371" href="slides4.html#5301" class="Bound">A</a> <a id="5373" href="Data.Product.html#1167" class="Function Operator">×</a> <a id="5375" href="slides4.html#5214" class="Postulate">Env</a> <a id="5379" href="slides4.html#5280" class="Bound">Γ</a><a id="5380" class="Symbol">)</a>
<a id="5384" class="Keyword">open</a> <a id="5389" href="slides4.html#5274" class="Module">Exec</a> <a id="5394" class="Keyword">public</a>
<a id="SizedTypes.execStm"></a><a id="5404" href="slides4.html#5404" class="Function">execStm</a> <a id="5412" class="Symbol">:</a> <a id="5414" class="Symbol">∀</a> <a id="5416" class="Symbol">{</a><a id="5417" href="slides4.html#5417" class="Bound">Γ</a><a id="5418" class="Symbol">}</a> <a id="5420" class="Symbol">{</a><a id="5421" href="slides4.html#5421" class="Bound">i</a><a id="5422" class="Symbol">}</a> <a id="5424" class="Symbol">(</a><a id="5425" href="slides4.html#5425" class="Bound">s</a> <a id="5427" class="Symbol">:</a> <a id="5429" href="slides4.html#5194" class="Postulate">Stm</a> <a id="5433" href="slides4.html#5417" class="Bound">Γ</a><a id="5434" class="Symbol">)</a> <a id="5436" class="Symbol">→</a> <a id="5438" href="slides4.html#5274" class="Record">Exec</a> <a id="5443" class="Symbol">{</a><a id="5444" href="slides4.html#5417" class="Bound">Γ</a><a id="5445" class="Symbol">}</a> <a id="5447" href="slides4.html#5421" class="Bound">i</a> <a id="5449" href="Agda.Builtin.Unit.html#137" class="Record">⊤</a>
<a id="5453" href="slides4.html#5404" class="Function">execStm</a> <a id="5461" class="Symbol">=</a> <a id="5463" href="slides4.html#5158" class="Postulate">⋯</a>
<a id="SizedTypes.execPrg"></a><a id="5468" href="slides4.html#5468" class="Function">execPrg</a> <a id="5476" class="Symbol">:</a> <a id="5478" class="Symbol">∀</a> <a id="5480" class="Symbol">{</a><a id="5481" href="slides4.html#5481" class="Bound">i</a><a id="5482" class="Symbol">}</a> <a id="5484" class="Symbol">(</a><a id="5485" href="slides4.html#5485" class="Bound">prg</a> <a id="5489" class="Symbol">:</a> <a id="5491" href="slides4.html#5234" class="Postulate">Program</a><a id="5498" class="Symbol">)</a> <a id="5500" class="Symbol">→</a> <a id="5502" href="slides4.html#4470" class="Record">Delay</a> <a id="5508" href="slides4.html#5481" class="Bound">i</a> <a id="5510" href="Agda.Builtin.Int.html#219" class="Datatype">ℤ</a>
<a id="5514" href="slides4.html#5468" class="Function">execPrg</a> <a id="5522" href="slides4.html#5522" class="Bound">prg</a> <a id="5526" class="Symbol">=</a> <a id="5528" href="slides4.html#5158" class="Postulate">⋯</a>
</pre>
<p>See <a href="https://jespercockx.github.io/ohrid19-agda/src/V3/html/V3.Interpreter.html">V3/Interpreter.agda</a> for full code.</p>
</section><section id="exercise" class="slide level2">
<h2>Exercise</h2>
<p>Now you should be ready to add a bigger new feature:</p>
<ul>
<li>A new control operator: <code>if</code> statements, <code>do/while</code> loops, <code>for</code>, <code>switch</code>, …</li>
<li>New types: <code>char</code>, <code>bool</code>, …</li>
<li>New programming concepts: function calls, pointers (hard!), …</li>
</ul>
<p>Extend the syntax, the typechecker, and the interpreter with rules for your new feature.</p>
</section></section>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//lib/js/head.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// Push each slide change to the browser history
history: true,
// Vertical centering of slides
center: false,
// Transition style
transition: 'linear', // none/fade/slide/convex/concave/zoom
// The "normal" size of the presentation, aspect ratio will be preserved
// when the presentation is scaled to fit different resolutions. Can be
// specified using percentage units.
width: 1280,
height: 720,
// Factor of the display size that should remain empty around the content
margin: 0.2,
math: {
mathjax: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js',
config: 'TeX-AMS_HTML-full',
tex2jax: {
inlineMath: [['\\(','\\)']],
displayMath: [['\\[','\\]']],
balanceBraces: true,
processEscapes: false,
processRefs: true,
processEnvironments: true,
preview: 'TeX',
skipTags: ['script','noscript','style','textarea','pre','code'],
ignoreClass: 'tex2jax_ignore',
processClass: 'tex2jax_process'
},
},
// Optional reveal.js plugins
dependencies: [
{ src: 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//plugin/zoom-js/zoom.js', async: true },
{ src: 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//plugin/math/math.js', async: true },
{ src: 'https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.7.0//plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>