-
Notifications
You must be signed in to change notification settings - Fork 0
/
Records.html
1176 lines (1004 loc) · 195 KB
/
Records.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
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="coqdoc.css" rel="stylesheet" type="text/css"/>
<title>Records: Adding Records to STLC</title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<div id="page">
<div id="header">
</div>
<div id="main">
<h1 class="libtitle">Records<span class="subtitle">Adding Records to STLC</span></h1>
<div class="code code-tight">
</div>
<div class="doc">
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Require</span> <span class="id" type="keyword">Import</span> <a class="idref" href="Maps.html#"><span class="id" type="library">Maps</span></a>.<br/>
<span class="id" type="keyword">Require</span> <span class="id" type="keyword">Import</span> <a class="idref" href="Imp.html#"><span class="id" type="library">Imp</span></a>.<br/>
<span class="id" type="keyword">Require</span> <span class="id" type="keyword">Import</span> <a class="idref" href="Smallstep.html#"><span class="id" type="library">Smallstep</span></a>.<br/>
<span class="id" type="keyword">Require</span> <span class="id" type="keyword">Import</span> <a class="idref" href="Stlc.html#"><span class="id" type="library">Stlc</span></a>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab691"></a><h1 class="section">Adding Records</h1>
<div class="paragraph"> </div>
We saw in chapter <a href="MoreStlc.html"><span class="inlineref">MoreStlc</span></a> how records can be treated as just
syntactic sugar for nested uses of products. This is OK for
simple examples, but the encoding is informal (in reality, if we
actually treated records this way, it would be carried out in the
parser, which we are eliding here), and anyway it is not very
efficient. So it is also interesting to see how records can be
treated as first-class citizens of the language. This chapter
shows how.
<div class="paragraph"> </div>
Recall the informal definitions we gave before:
<div class="paragraph"> </div>
<div class="paragraph"> </div>
Syntax:
<pre>
t ::= Terms:
| {i<sub>1</sub>=t<sub>1</sub>, ..., in=tn} record
| t.i projection
| ...
v ::= Values:
| {i<sub>1</sub>=v<sub>1</sub>, ..., in=vn} record value
| ...
T ::= Types:
| {i<sub>1</sub>:T<sub>1</sub>, ..., in:Tn} record type
| ...
</pre>
Reduction:
<center><table class="infrule">
<tr class="infruleassumption">
<td class="infrule">ti <span style="font-family: arial;">⇒</span> ti' (ST_Rcd)</td>
<td class="infrulenamecol" rowspan="3">
</td></tr>
<tr class="infrulemiddle">
<td class="infrule"><hr /></td>
</tr>
<tr class="infruleassumption">
<td class="infrule">{i<sub>1</sub>=v<sub>1</sub>, ..., im=vm, in=tn, ...} <span style="font-family: arial;">⇒</span> {i<sub>1</sub>=v<sub>1</sub>, ..., im=vm, in=tn', ...}</td>
<td></td>
</td>
</table></center><center><table class="infrule">
<tr class="infruleassumption">
<td class="infrule">t<sub>1</sub> <span style="font-family: arial;">⇒</span> t<sub>1</sub>'</td>
<td class="infrulenamecol" rowspan="3">
(ST_Proj1)
</td></tr>
<tr class="infrulemiddle">
<td class="infrule"><hr /></td>
</tr>
<tr class="infruleassumption">
<td class="infrule">t<sub>1</sub>.i <span style="font-family: arial;">⇒</span> t<sub>1</sub>'.i</td>
<td></td>
</td>
</table></center><center><table class="infrule">
<tr class="infruleassumption">
<td class="infrule"> </td>
<td class="infrulenamecol" rowspan="3">
(ST_ProjRcd)
</td></tr>
<tr class="infrulemiddle">
<td class="infrule"><hr /></td>
</tr>
<tr class="infruleassumption">
<td class="infrule">{..., i=vi, ...}.i <span style="font-family: arial;">⇒</span> vi</td>
<td></td>
</td>
</table></center> Typing:
<center><table class="infrule">
<tr class="infruleassumption">
<td class="infrule"><span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> t<sub>1</sub> : T<sub>1</sub> ... <span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> tn : Tn</td>
<td class="infrulenamecol" rowspan="3">
(T_Rcd)
</td></tr>
<tr class="infrulemiddle">
<td class="infrule"><hr /></td>
</tr>
<tr class="infruleassumption">
<td class="infrule"><span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> {i<sub>1</sub>=t<sub>1</sub>, ..., in=tn} : {i<sub>1</sub>:T<sub>1</sub>, ..., in:Tn}</td>
<td></td>
</td>
</table></center><center><table class="infrule">
<tr class="infruleassumption">
<td class="infrule"><span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> t : {..., i:Ti, ...}</td>
<td class="infrulenamecol" rowspan="3">
(T_Proj)
</td></tr>
<tr class="infrulemiddle">
<td class="infrule"><hr /></td>
</tr>
<tr class="infruleassumption">
<td class="infrule"><span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> t.i : Ti</td>
<td></td>
</td>
</table></center>
</div>
<div class="code code-tight">
<br/>
</div>
<div class="doc">
<a name="lab692"></a><h1 class="section">Formalizing Records</h1>
</div>
<div class="code code-space">
<br/>
<span class="id" type="keyword">Module</span> <a name="STLCExtendedRecords"><span class="id" type="module">STLCExtendedRecords</span></a>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab693"></a><h3 class="section">Syntax and Operational Semantics</h3>
<div class="paragraph"> </div>
The most obvious way to formalize the syntax of record types would
be this:
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Module</span> <a name="STLCExtendedRecords.FirstTry"><span class="id" type="module">FirstTry</span></a>.<br/>
<br/>
<span class="id" type="keyword">Definition</span> <a name="STLCExtendedRecords.FirstTry.alist"><span class="id" type="definition">alist</span></a> (<span class="id" type="var">X</span> : <span class="id" type="keyword">Type</span>) := <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#list"><span class="id" type="inductive">list</span></a> (<a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> * <a class="idref" href="Records.html#X"><span class="id" type="variable">X</span></a>).<br/>
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.FirstTry.ty"><span class="id" type="inductive">ty</span></a> : <span class="id" type="keyword">Type</span> :=<br/>
| <a name="STLCExtendedRecords.FirstTry.TBase"><span class="id" type="constructor">TBase</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a><br/>
| <a name="STLCExtendedRecords.FirstTry.TArrow"><span class="id" type="constructor">TArrow</span></a> : <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a><br/>
| <a name="STLCExtendedRecords.FirstTry.TRcd"><span class="id" type="constructor">TRcd</span></a> : (<a class="idref" href="Records.html#STLCExtendedRecords.FirstTry.alist"><span class="id" type="definition">alist</span></a> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a>) <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a>.<br/>
<br/>
</div>
<div class="doc">
Unfortunately, we encounter here a limitation in Coq: this type
does not automatically give us the induction principle we expect:
the induction hypothesis in the <span class="inlinecode"><span class="id" type="var">TRcd</span></span> case doesn't give us
any information about the <span class="inlinecode"><span class="id" type="var">ty</span></span> elements of the list, making it
useless for the proofs we want to do.
</div>
<div class="code code-tight">
<br/>
<span class="comment">(* Check ty_ind.<br/>
====><br/>
ty_ind :<br/>
forall P : ty -> Prop,<br/>
(forall i : id, P (TBase i)) -><br/>
(forall t : ty, P t -> forall t<sub>0</sub> : ty, P t<sub>0</sub> <br/>
-> P (TArrow t t<sub>0</sub>)) -><br/>
(forall a : alist ty, P (TRcd a)) -> <span class="comment">(* ??? *)</span><br/>
forall t : ty, P t<br/>
*)</span><br/>
<br/>
<span class="id" type="keyword">End</span> <a class="idref" href="Records.html#STLCExtendedRecords.FirstTry"><span class="id" type="module">FirstTry</span></a>.<br/>
<br/>
</div>
<div class="doc">
It is possible to get a better induction principle out of Coq, but
the details of how this is done are not very pretty, and the
principle we obtain is not as intuitive to use as the ones Coq
generates automatically for simple <span class="inlinecode"><span class="id" type="keyword">Inductive</span></span> definitions.
<div class="paragraph"> </div>
Fortunately, there is a different way of formalizing records that
is, in some ways, even simpler and more natural: instead of using
the standard Coq <span class="inlinecode"><span class="id" type="var">list</span></span> type, we can essentially incorporate its
constructors ("nil" and "cons") in the syntax of our types.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a> : <span class="id" type="keyword">Type</span> :=<br/>
| <a name="STLCExtendedRecords.TBase"><span class="id" type="constructor">TBase</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a><br/>
| <a name="STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> : <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a><br/>
| <a name="STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a> : <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a><br/>
| <a name="STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#ty"><span class="id" type="inductive">ty</span></a>.<br/>
<br/>
</div>
<div class="doc">
Similarly, at the level of terms, we have constructors <span class="inlinecode"><span class="id" type="var">trnil</span></span>,
for the empty record, and <span class="inlinecode"><span class="id" type="var">trcons</span></span>, which adds a single field to
the front of a list of fields.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> : <span class="id" type="keyword">Type</span> :=<br/>
| <a name="STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a><br/>
| <a name="STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> : <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a><br/>
| <a name="STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a><br/>
<span class="comment">(* records *)</span><br/>
| <a name="STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> : <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a><br/>
| <a name="STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a> : <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a><br/>
| <a name="STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#tm"><span class="id" type="inductive">tm</span></a>.<br/>
<br/>
</div>
<div class="doc">
Some examples...
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 0).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.f"><span class="id" type="abbreviation">f</span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 1).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.g"><span class="id" type="abbreviation">g</span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 2).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.l"><span class="id" type="abbreviation">l</span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 3).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a> := (<a class="idref" href="Records.html#STLCExtendedRecords.TBase"><span class="id" type="constructor">TBase</span></a> (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 4)).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a> := (<a class="idref" href="Records.html#STLCExtendedRecords.TBase"><span class="id" type="constructor">TBase</span></a> (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 5)).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.k"><span class="id" type="abbreviation">k</span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 6).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 7).<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.i2"><span class="id" type="abbreviation">i<sub>2</sub></span></a> := (<a class="idref" href="Maps.html#Id"><span class="id" type="constructor">Id</span></a> 8).<br/>
<br/>
</div>
<div class="doc">
<span class="inlinecode">{</span> <span class="inlinecode"><span class="id" type="var">i<sub>1</sub></span>:<span class="id" type="var">A</span></span> <span class="inlinecode">}</span>
</div>
<div class="code code-tight">
<br/>
<span class="comment">(* Check (TRCons i<sub>1</sub> A TRNil). *)</span><br/>
<br/>
</div>
<div class="doc">
<span class="inlinecode">{</span> <span class="inlinecode"><span class="id" type="var">i<sub>1</sub></span>:<span class="id" type="var">A</span><span style="font-family: arial;">→</span><span class="id" type="var">B</span>,</span> <span class="inlinecode"><span class="id" type="var">i<sub>2</sub></span>:<span class="id" type="var">A</span></span> <span class="inlinecode">}</span>
</div>
<div class="code code-tight">
<br/>
<span class="comment">(* Check (TRCons i<sub>1</sub> (TArrow A B)<br/>
(TRCons i<sub>2</sub> A TRNil)). *)</span><br/>
<br/>
</div>
<div class="doc">
<a name="lab694"></a><h3 class="section">Well-Formedness</h3>
<div class="paragraph"> </div>
One issue with generalizing the abstract syntax for records from
lists to the nil/cons presentation is that it introduces the
possibility of writing strange types like this...
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Definition</span> <a name="STLCExtendedRecords.weird_type"><span class="id" type="definition">weird_type</span></a> := <a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Imp.html#X"><span class="id" type="definition">X</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a>.<br/>
<br/>
</div>
<div class="doc">
where the "tail" of a record type is not actually a record type!
<div class="paragraph"> </div>
We'll structure our typing judgement so that no ill-formed types
like <span class="inlinecode"><span class="id" type="var">weird_type</span></span> are ever assigned to terms. To support this, we
define predicates <span class="inlinecode"><span class="id" type="var">record_ty</span></span> and <span class="inlinecode"><span class="id" type="var">record_tm</span></span>, which identify
record types and terms, and <span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span> which rules out the
ill-formed types.
<div class="paragraph"> </div>
First, a type is a record type if it is built with just <span class="inlinecode"><span class="id" type="var">TRNil</span></span>
and <span class="inlinecode"><span class="id" type="var">TRCons</span></span> at the outermost level.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.record_ty"><span class="id" type="inductive">record_ty</span></a> : <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.RTnil"><span class="id" type="constructor">RTnil</span></a> :<br/>
<a class="idref" href="Records.html#record_ty"><span class="id" type="inductive">record_ty</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a><br/>
| <a name="STLCExtendedRecords.RTcons"><span class="id" type="constructor">RTcons</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">T<sub>1</sub></span> <span class="id" type="var">T<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#record_ty"><span class="id" type="inductive">record_ty</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a>).<br/>
<br/>
</div>
<div class="doc">
With this, we can define well-formed types.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> : <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.wfTBase"><span class="id" type="constructor">wfTBase</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span>,<br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TBase"><span class="id" type="constructor">TBase</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a>)<br/>
| <a name="STLCExtendedRecords.wfTArrow"><span class="id" type="constructor">wfTArrow</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">T<sub>1</sub></span> <span class="id" type="var">T<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.wfTRNil"><span class="id" type="constructor">wfTRNil</span></a> :<br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a><br/>
| <a name="STLCExtendedRecords.wfTRCons"><span class="id" type="constructor">wfTRCons</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">T<sub>1</sub></span> <span class="id" type="var">T<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.record_ty"><span class="id" type="inductive">record_ty</span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a>).<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <a class="idref" href="Records.html#record_ty"><span class="id" type="inductive">record_ty</span></a> <a class="idref" href="Records.html#well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a>.<br/>
<br/>
</div>
<div class="doc">
Note that <span class="inlinecode"><span class="id" type="var">record_ty</span></span> and <span class="inlinecode"><span class="id" type="var">record_tm</span></span> are not recursive — they
just check the outermost constructor. The <span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span>
property, on the other hand, verifies that the whole type is well
formed in the sense that the tail of every record (the second
argument to <span class="inlinecode"><span class="id" type="var">TRCons</span></span>) is a record.
<div class="paragraph"> </div>
Of course, we should also be concerned about ill-formed terms, not
just types; but typechecking can rules those out without the help
of an extra <span class="inlinecode"><span class="id" type="var">well_formed_tm</span></span> definition because it already
examines the structure of terms. All we need is an analog of
<span class="inlinecode"><span class="id" type="var">record_ty</span></span> saying that a term is a record term if it is built
with <span class="inlinecode"><span class="id" type="var">trnil</span></span> and <span class="inlinecode"><span class="id" type="var">trcons</span></span>.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.record_tm"><span class="id" type="inductive">record_tm</span></a> : <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.rtnil"><span class="id" type="constructor">rtnil</span></a> :<br/>
<a class="idref" href="Records.html#record_tm"><span class="id" type="inductive">record_tm</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a><br/>
| <a name="STLCExtendedRecords.rtcons"><span class="id" type="constructor">rtcons</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#record_tm"><span class="id" type="inductive">record_tm</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>).<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <a class="idref" href="Records.html#record_tm"><span class="id" type="inductive">record_tm</span></a>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab695"></a><h3 class="section">Substitution</h3>
<div class="paragraph"> </div>
Substitution extends easily.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Fixpoint</span> <a name="STLCExtendedRecords.subst"><span class="id" type="definition">subst</span></a> (<span class="id" type="var">x</span>:<a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a>) (<span class="id" type="var">s</span>:<a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a>) (<span class="id" type="var">t</span>:<a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a>) : <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> :=<br/>
<span class="id" type="keyword">match</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <span class="id" type="keyword">with</span><br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <span class="id" type="var">y</span> ⇒ <span class="id" type="keyword">if</span> <a class="idref" href="Maps.html#beq_id"><span class="id" type="definition">beq_id</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <span class="id" type="var">y</span> <span class="id" type="keyword">then</span> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="keyword">else</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a><br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <span class="id" type="var">y</span> <span class="id" type="var">T</span> <span class="id" type="var">t<sub>1</sub></span> ⇒ <a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <span class="id" type="var">y</span> <span class="id" type="var">T</span><br/>
(<span class="id" type="keyword">if</span> <a class="idref" href="Maps.html#beq_id"><span class="id" type="definition">beq_id</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <span class="id" type="var">y</span> <span class="id" type="keyword">then</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="keyword">else</span> (<a class="idref" href="Records.html#subst"><span class="id" type="definition">subst</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="var">t<sub>1</sub></span>))<br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span> ⇒ <a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> (<a class="idref" href="Records.html#subst"><span class="id" type="definition">subst</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="var">t<sub>1</sub></span>) (<a class="idref" href="Records.html#subst"><span class="id" type="definition">subst</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="var">t<sub>2</sub></span>)<br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">i</span> ⇒ <a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> (<a class="idref" href="Records.html#subst"><span class="id" type="definition">subst</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="var">t<sub>1</sub></span>) <span class="id" type="var">i</span><br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a> ⇒ <a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a><br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <span class="id" type="var">i</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">tr<sub>1</sub></span> ⇒ <a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <span class="id" type="var">i</span> (<a class="idref" href="Records.html#subst"><span class="id" type="definition">subst</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="var">t<sub>1</sub></span>) (<a class="idref" href="Records.html#subst"><span class="id" type="definition">subst</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#s"><span class="id" type="variable">s</span></a> <span class="id" type="var">tr<sub>1</sub></span>)<br/>
<span class="id" type="keyword">end</span>.<br/>
<br/>
<span class="id" type="keyword">Notation</span> "'[' x ':=' s ']' t" := (<a class="idref" href="Records.html#STLCExtendedRecords.subst"><span class="id" type="definition">subst</span></a> <span class="id" type="var">x</span> <span class="id" type="var">s</span> <span class="id" type="var">t</span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 20).<br/>
<br/>
</div>
<div class="doc">
<a name="lab696"></a><h3 class="section">Reduction</h3>
<div class="paragraph"> </div>
A record is a value if all of its fields are.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> : <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.v_abs"><span class="id" type="constructor">v_abs</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">T<sub>11</sub></span> <span class="id" type="var">t<sub>12</sub></span>,<br/>
<a class="idref" href="Records.html#value"><span class="id" type="inductive">value</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a> <a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.v_rnil"><span class="id" type="constructor">v_rnil</span></a> : <a class="idref" href="Records.html#value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a><br/>
| <a name="STLCExtendedRecords.v_rcons"><span class="id" type="constructor">v_rcons</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">v<sub>1</sub></span> <span class="id" type="var">vr</span>,<br/>
<a class="idref" href="Records.html#value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#vr"><span class="id" type="variable">vr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#value"><span class="id" type="inductive">value</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <a class="idref" href="Records.html#vr"><span class="id" type="variable">vr</span></a>).<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <a class="idref" href="Records.html#value"><span class="id" type="inductive">value</span></a>.<br/>
<br/>
</div>
<div class="doc">
To define reduction, we'll need a utility function for extracting
one field from record term:
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Fixpoint</span> <a name="STLCExtendedRecords.tlookup"><span class="id" type="definition">tlookup</span></a> (<span class="id" type="var">i</span>:<a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a>) (<span class="id" type="var">tr</span>:<a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a>) : <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#option"><span class="id" type="inductive">option</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> :=<br/>
<span class="id" type="keyword">match</span> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <span class="id" type="keyword">with</span><br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <span class="id" type="var">i'</span> <span class="id" type="var">t</span> <span class="id" type="var">tr'</span> ⇒ <span class="id" type="keyword">if</span> <a class="idref" href="Maps.html#beq_id"><span class="id" type="definition">beq_id</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <span class="id" type="var">i'</span> <span class="id" type="keyword">then</span> <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <span class="id" type="var">t</span> <span class="id" type="keyword">else</span> <a class="idref" href="Records.html#tlookup"><span class="id" type="definition">tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <span class="id" type="var">tr'</span><br/>
| <span class="id" type="var">_</span> ⇒ <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#None"><span class="id" type="constructor">None</span></a><br/>
<span class="id" type="keyword">end</span>.<br/>
<br/>
</div>
<div class="doc">
The <span class="inlinecode"><span class="id" type="var">step</span></span> function uses this term-level lookup function in the
projection rule.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Reserved Notation</span> "t<sub>1</sub> '<span style="font-family: arial;">⇒</span>' t<sub>2</sub>" (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 40).<br/>
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.step"><span class="id" type="inductive">step</span></a> : <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.ST_AppAbs"><span class="id" type="constructor">ST_AppAbs</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">T<sub>11</sub></span> <span class="id" type="var">t<sub>12</sub></span> <span class="id" type="var">v<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#v<sub>2</sub>"><span class="id" type="variable">v<sub>2</sub></span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a> <a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a>) <a class="idref" href="Records.html#v<sub>2</sub>"><span class="id" type="variable">v<sub>2</sub></span></a>) <span style="font-family: arial;">⇒</span> ([<a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a>:=<a class="idref" href="Records.html#v<sub>2</sub>"><span class="id" type="variable">v<sub>2</sub></span></a>]<a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.ST_App1"><span class="id" type="constructor">ST_App1</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>1</sub>'</span> <span class="id" type="var">t<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#t<sub>1</sub>'"><span class="id" type="variable">t<sub>1</sub>'</span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>) <span style="font-family: arial;">⇒</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#t<sub>1</sub>'"><span class="id" type="variable">t<sub>1</sub>'</span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.ST_App2"><span class="id" type="constructor">ST_App2</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">v<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span> <span class="id" type="var">t<sub>2</sub>'</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#t<sub>2</sub>'"><span class="id" type="variable">t<sub>2</sub>'</span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>) <span style="font-family: arial;">⇒</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>'"><span class="id" type="variable">t<sub>2</sub>'</span></a>)<br/>
| <a name="STLCExtendedRecords.ST_Proj1"><span class="id" type="constructor">ST_Proj1</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>1</sub>'</span> <span class="id" type="var">i</span>,<br/>
<a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#t<sub>1</sub>'"><span class="id" type="variable">t<sub>1</sub>'</span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a>) <span style="font-family: arial;">⇒</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <a class="idref" href="Records.html#t<sub>1</sub>'"><span class="id" type="variable">t<sub>1</sub>'</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a>)<br/>
| <a name="STLCExtendedRecords.ST_ProjRcd"><span class="id" type="constructor">ST_ProjRcd</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">tr</span> <span class="id" type="var">i</span> <span class="id" type="var">vi</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.tlookup"><span class="id" type="definition">tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#vi"><span class="id" type="variable">vi</span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a>) <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#vi"><span class="id" type="variable">vi</span></a><br/>
| <a name="STLCExtendedRecords.ST_Rcd_Head"><span class="id" type="constructor">ST_Rcd_Head</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>1</sub>'</span> <span class="id" type="var">tr<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#t<sub>1</sub>'"><span class="id" type="variable">t<sub>1</sub>'</span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#tr<sub>2</sub>"><span class="id" type="variable">tr<sub>2</sub></span></a>) <span style="font-family: arial;">⇒</span> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#t<sub>1</sub>'"><span class="id" type="variable">t<sub>1</sub>'</span></a> <a class="idref" href="Records.html#tr<sub>2</sub>"><span class="id" type="variable">tr<sub>2</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.ST_Rcd_Tail"><span class="id" type="constructor">ST_Rcd_Tail</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">v<sub>1</sub></span> <span class="id" type="var">tr<sub>2</sub></span> <span class="id" type="var">tr<sub>2</sub>'</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#tr<sub>2</sub>"><span class="id" type="variable">tr<sub>2</sub></span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#tr<sub>2</sub>'"><span class="id" type="variable">tr<sub>2</sub>'</span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <a class="idref" href="Records.html#tr<sub>2</sub>"><span class="id" type="variable">tr<sub>2</sub></span></a>) <span style="font-family: arial;">⇒</span> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#v<sub>1</sub>"><span class="id" type="variable">v<sub>1</sub></span></a> <a class="idref" href="Records.html#tr<sub>2</sub>'"><span class="id" type="variable">tr<sub>2</sub>'</span></a>)<br/>
<br/>
<span class="id" type="keyword">where</span> "t<sub>1</sub> '<span style="font-family: arial;">⇒</span>' t<sub>2</sub>" := (<a class="idref" href="Records.html#step"><span class="id" type="inductive">step</span></a> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span>).<br/>
<br/>
<span class="id" type="keyword">Notation</span> <a name="STLCExtendedRecords.multistep"><span class="id" type="abbreviation">multistep</span></a> := (<a class="idref" href="Smallstep.html#multi"><span class="id" type="inductive">multi</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.step"><span class="id" type="inductive">step</span></a>).<br/>
<span class="id" type="keyword">Notation</span> "t<sub>1</sub> '<span style="font-family: arial;">⇒*</span>' t<sub>2</sub>" := (<a class="idref" href="Records.html#STLCExtendedRecords.multistep"><span class="id" type="abbreviation">multistep</span></a> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span>) (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 40).<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <a class="idref" href="Records.html#step"><span class="id" type="inductive">step</span></a>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab697"></a><h3 class="section">Typing</h3>
<div class="paragraph"> </div>
Next we define the typing rules. These are nearly direct
transcriptions of the inference rules shown above: the only
significant difference is the use of <span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span>. In the
informal presentation we used a grammar that only allowed
well-formed record types, so we didn't have to add a separate
check.
<div class="paragraph"> </div>
One sanity condition that we'd like to maintain is that, whenever
<span class="inlinecode"><span class="id" type="var">has_type</span></span> <span class="inlinecode"><span style="font-family: serif; font-size:85%;">Γ</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">T</span></span> holds, will also be the case that
<span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span> <span class="inlinecode"><span class="id" type="var">T</span></span>, so that <span class="inlinecode"><span class="id" type="var">has_type</span></span> never assigns ill-formed
types to terms. In fact, we prove this theorem below. However,
we don't want to clutter the definition of <span class="inlinecode"><span class="id" type="var">has_type</span></span> with
unnecessary uses of <span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span>. Instead, we place
<span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span> checks only where needed: where an inductive call
to <span class="inlinecode"><span class="id" type="var">has_type</span></span> won't already be checking the well-formedness of a
type. For example, we check <span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span> <span class="inlinecode"><span class="id" type="var">T</span></span> in the <span class="inlinecode"><span class="id" type="var">T_Var</span></span>
case, because there is no inductive <span class="inlinecode"><span class="id" type="var">has_type</span></span> call that would
enforce this. Similarly, in the <span class="inlinecode"><span class="id" type="var">T_Abs</span></span> case, we require a proof
of <span class="inlinecode"><span class="id" type="var">well_formed_ty</span></span> <span class="inlinecode"><span class="id" type="var">T<sub>11</sub></span></span> because the inductive call to <span class="inlinecode"><span class="id" type="var">has_type</span></span>
only guarantees that <span class="inlinecode"><span class="id" type="var">T<sub>12</sub></span></span> is well-formed.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Fixpoint</span> <a name="STLCExtendedRecords.Tlookup"><span class="id" type="definition">Tlookup</span></a> (<span class="id" type="var">i</span>:<a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a>) (<span class="id" type="var">Tr</span>:<a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a>) : <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#option"><span class="id" type="inductive">option</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a> :=<br/>
<span class="id" type="keyword">match</span> <a class="idref" href="Records.html#Tr"><span class="id" type="variable">Tr</span></a> <span class="id" type="keyword">with</span><br/>
| <a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <span class="id" type="var">i'</span> <span class="id" type="var">T</span> <span class="id" type="var">Tr'</span> ⇒<br/>
<span class="id" type="keyword">if</span> <a class="idref" href="Maps.html#beq_id"><span class="id" type="definition">beq_id</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <span class="id" type="var">i'</span> <span class="id" type="keyword">then</span> <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <span class="id" type="var">T</span> <span class="id" type="keyword">else</span> <a class="idref" href="Records.html#Tlookup"><span class="id" type="definition">Tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <span class="id" type="var">Tr'</span><br/>
| <span class="id" type="var">_</span> ⇒ <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#None"><span class="id" type="constructor">None</span></a><br/>
<span class="id" type="keyword">end</span>.<br/>
<br/>
<span class="id" type="keyword">Definition</span> <a name="STLCExtendedRecords.context"><span class="id" type="definition">context</span></a> := <a class="idref" href="Maps.html#partial_map"><span class="id" type="definition">partial_map</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a>.<br/>
<br/>
<span class="id" type="keyword">Reserved Notation</span> "Gamma '<span style="font-family: arial;">⊢</span>' t '∈' T" (<span class="id" type="tactic">at</span> <span class="id" type="var">level</span> 40).<br/>
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.has_type"><span class="id" type="inductive">has_type</span></a> : <a class="idref" href="Records.html#STLCExtendedRecords.context"><span class="id" type="definition">context</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.T_Var"><span class="id" type="constructor">T_Var</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">x</span> <span class="id" type="var">T</span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a>) ∈ <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a><br/>
| <a name="STLCExtendedRecords.T_Abs"><span class="id" type="constructor">T_Abs</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">x</span> <span class="id" type="var">T<sub>11</sub></span> <span class="id" type="var">T<sub>12</sub></span> <span class="id" type="var">t<sub>12</sub></span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a> <span style="font-family: arial;">→</span><br/>
(<a class="idref" href="Maps.html#update"><span class="id" type="definition">update</span></a> <span style="font-family: serif; font-size:85%;">Γ</span> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a>) <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a> ∈ <a class="idref" href="Records.html#T<sub>12</sub>"><span class="id" type="variable">T<sub>12</sub></span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a> <a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a>) ∈ (<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a> <a class="idref" href="Records.html#T<sub>12</sub>"><span class="id" type="variable">T<sub>12</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.T_App"><span class="id" type="constructor">T_App</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">T<sub>1</sub></span> <span class="id" type="var">T<sub>2</sub></span> <span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> ∈ (<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a>) <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a> ∈ <a class="idref" href="Records.html#T<sub>1</sub>"><span class="id" type="variable">T<sub>1</sub></span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>) ∈ <a class="idref" href="Records.html#T<sub>2</sub>"><span class="id" type="variable">T<sub>2</sub></span></a><br/>
<span class="comment">(* records: *)</span><br/>
| <a name="STLCExtendedRecords.T_Proj"><span class="id" type="constructor">T_Proj</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">i</span> <span class="id" type="var">t</span> <span class="id" type="var">Ti</span> <span class="id" type="var">Tr</span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#Tr"><span class="id" type="variable">Tr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.Tlookup"><span class="id" type="definition">Tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#Tr"><span class="id" type="variable">Tr</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#Ti"><span class="id" type="variable">Ti</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> (<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a>) ∈ <a class="idref" href="Records.html#Ti"><span class="id" type="variable">Ti</span></a><br/>
| <a name="STLCExtendedRecords.T_RNil"><span class="id" type="constructor">T_RNil</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a> ∈ <a class="idref" href="Records.html#STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a><br/>
| <a name="STLCExtendedRecords.T_RCons"><span class="id" type="constructor">T_RCons</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">i</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span> <span class="id" type="var">tr</span> <span class="id" type="var">Tr</span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> ∈ <a class="idref" href="Records.html#Tr"><span class="id" type="variable">Tr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.record_ty"><span class="id" type="inductive">record_ty</span></a> <a class="idref" href="Records.html#Tr"><span class="id" type="variable">Tr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.record_tm"><span class="id" type="inductive">record_tm</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a>) ∈ (<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <a class="idref" href="Records.html#Tr"><span class="id" type="variable">Tr</span></a>)<br/>
<br/>
<span class="id" type="keyword">where</span> "Gamma '<span style="font-family: arial;">⊢</span>' t '∈' T" := (<a class="idref" href="Records.html#has_type"><span class="id" type="inductive">has_type</span></a> <span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span>).<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <a class="idref" href="Records.html#has_type"><span class="id" type="inductive">has_type</span></a>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab698"></a><h2 class="section">Examples</h2>
<div class="paragraph"> </div>
<a name="lab699"></a><h4 class="section">Exercise: 2 stars (examples)</h4>
Finish the proofs below. Feel free to use Coq's automation
features in this proof. However, if you are not confident about
how the type system works, you may want to carry out the proofs
first using the basic features (<span class="inlinecode"><span class="id" type="tactic">apply</span></span> instead of <span class="inlinecode"><span class="id" type="tactic">eapply</span></span>, in
particular) and then perhaps compress it using automation. Before
starting to prove anything, make sure you understand what it is
saying.
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.typing_example_2"><span class="id" type="lemma">typing_example_2</span></a> :<br/>
<a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <span style="font-family: arial;">⊢</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a>)<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i2"><span class="id" type="abbreviation">i<sub>2</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a>)<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a>))<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a>) <a class="idref" href="Records.html#STLCExtendedRecords.i2"><span class="id" type="abbreviation">i<sub>2</sub></span></a>))<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a>))<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i2"><span class="id" type="abbreviation">i<sub>2</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a>))<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a>))) ∈<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a>).<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="comment">(* FILL IN HERE *)</span> <span class="id" type="var">Admitted</span>.<br/>
<br/>
<span class="id" type="keyword">Example</span> <a name="STLCExtendedRecords.typing_nonexample"><span class="id" type="definition">typing_nonexample</span></a> :<br/>
¬ <span style="font-family: arial;">∃</span><span class="id" type="var">T</span>,<br/>
(<a class="idref" href="Maps.html#update"><span class="id" type="definition">update</span></a> <a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i2"><span class="id" type="abbreviation">i<sub>2</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TArrow"><span class="id" type="constructor">TArrow</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a>)<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a>)) <span style="font-family: arial;">⊢</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.B"><span class="id" type="abbreviation">B</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a>)) (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a>)) ∈<br/>
<a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="comment">(* FILL IN HERE *)</span> <span class="id" type="var">Admitted</span>.<br/>
<br/>
<span class="id" type="keyword">Example</span> <a name="STLCExtendedRecords.typing_nonexample_2"><span class="id" type="definition">typing_nonexample_2</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">y</span>,<br/>
¬ <span style="font-family: arial;">∃</span><span class="id" type="var">T</span>,<br/>
(<a class="idref" href="Maps.html#update"><span class="id" type="definition">update</span></a> <a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <a class="idref" href="Records.html#y"><span class="id" type="variable">y</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a>) <span style="font-family: arial;">⊢</span><br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.TRCons"><span class="id" type="constructor">TRCons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a> <a class="idref" href="Records.html#STLCExtendedRecords.A"><span class="id" type="abbreviation">A</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.TRNil"><span class="id" type="constructor">TRNil</span></a>)<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.a"><span class="id" type="abbreviation">a</span></a>) <a class="idref" href="Records.html#STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a>))<br/>
(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i1"><span class="id" type="abbreviation">i<sub>1</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#y"><span class="id" type="variable">y</span></a>) (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.i2"><span class="id" type="abbreviation">i<sub>2</sub></span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#y"><span class="id" type="variable">y</span></a>) <a class="idref" href="Records.html#STLCExtendedRecords.trnil"><span class="id" type="constructor">trnil</span></a>))) ∈<br/>
<a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a>.<br/>
<span class="id" type="keyword">Proof</span>.<br/>
<span class="comment">(* FILL IN HERE *)</span> <span class="id" type="var">Admitted</span>.<br/>
<br/>
</div>
<div class="doc">
<a name="lab700"></a><h2 class="section">Properties of Typing</h2>
<div class="paragraph"> </div>
The proofs of progress and preservation for this system are
essentially the same as for the pure simply typed lambda-calculus,
but we need to add some technical lemmas involving records.
</div>
<div class="code code-tight">
<br/>
</div>
<div class="doc">
<a name="lab701"></a><h3 class="section">Well-Formedness</h3>
</div>
<div class="code code-space">
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.wf_rcd_lookup"><span class="id" type="lemma">wf_rcd_lookup</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">i</span> <span class="id" type="var">T</span> <span class="id" type="var">Ti</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.Tlookup"><span class="id" type="definition">Tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#Ti"><span class="id" type="variable">Ti</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#Ti"><span class="id" type="variable">Ti</span></a>.<br/>
<div class="togglescript" id="proofcontrol1" onclick="toggleDisplay('proof1');toggleDisplay('proofcontrol1')"><span class="show"></span></div>
<div class="proofscript" id="proof1" onclick="toggleDisplay('proof1');toggleDisplay('proofcontrol1')">
<span class="id" type="keyword">Proof</span> <span class="id" type="keyword">with</span> <span class="id" type="tactic">eauto</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">i</span> <span class="id" type="var">T</span>.<br/>
<span class="id" type="tactic">induction</span> <span class="id" type="var">T</span>; <span class="id" type="tactic">intros</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">solve_by_invert</span>.<br/>
- <span class="comment">(* TRCons *)</span><br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">H</span>. <span class="id" type="tactic">subst</span>. <span class="id" type="tactic">unfold</span> <a class="idref" href="Records.html#STLCExtendedRecords.Tlookup"><span class="id" type="definition">Tlookup</span></a> <span class="id" type="keyword">in</span> <span class="id" type="var">H<sub>0</sub></span>.<br/>
<span class="id" type="tactic">destruct</span> (<a class="idref" href="Maps.html#beq_id"><span class="id" type="definition">beq_id</span></a> <span class="id" type="var">i</span> <span class="id" type="var">i<sub>0</sub></span>)...<br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">H<sub>0</sub></span>. <span class="id" type="tactic">subst</span>... <span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.step_preserves_record_tm"><span class="id" type="lemma">step_preserves_record_tm</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">tr</span> <span class="id" type="var">tr'</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.record_tm"><span class="id" type="inductive">record_tm</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#tr'"><span class="id" type="variable">tr'</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.record_tm"><span class="id" type="inductive">record_tm</span></a> <a class="idref" href="Records.html#tr'"><span class="id" type="variable">tr'</span></a>.<br/>
<div class="togglescript" id="proofcontrol2" onclick="toggleDisplay('proof2');toggleDisplay('proofcontrol2')"><span class="show"></span></div>
<div class="proofscript" id="proof2" onclick="toggleDisplay('proof2');toggleDisplay('proofcontrol2')">
<span class="id" type="keyword">Proof</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">tr</span> <span class="id" type="var">tr'</span> <span class="id" type="var">Hrt</span> <span class="id" type="var">Hstp</span>.<br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">Hrt</span>; <span class="id" type="tactic">subst</span>; <span class="id" type="tactic">inversion</span> <span class="id" type="var">Hstp</span>; <span class="id" type="tactic">subst</span>; <span class="id" type="tactic">auto</span>.<br/>
<span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.has_type__wf"><span class="id" type="lemma">has_type__wf</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#STLCExtendedRecords.well_formed_ty"><span class="id" type="inductive">well_formed_ty</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a>.<br/>
<div class="togglescript" id="proofcontrol3" onclick="toggleDisplay('proof3');toggleDisplay('proofcontrol3')"><span class="show"></span></div>
<div class="proofscript" id="proof3" onclick="toggleDisplay('proof3');toggleDisplay('proofcontrol3')">
<span class="id" type="keyword">Proof</span> <span class="id" type="keyword">with</span> <span class="id" type="tactic">eauto</span>.<br/>
<span class="id" type="tactic">intros</span> <span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span> <span class="id" type="var">Htyp</span>.<br/>
<span class="id" type="tactic">induction</span> <span class="id" type="var">Htyp</span>...<br/>
- <span class="comment">(* T_App *)</span><br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">IHHtyp1</span>...<br/>
- <span class="comment">(* T_Proj *)</span><br/>
<span class="id" type="tactic">eapply</span> <a class="idref" href="Records.html#STLCExtendedRecords.wf_rcd_lookup"><span class="id" type="lemma">wf_rcd_lookup</span></a>...<br/>
<span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
</div>
<div class="doc">
<a name="lab702"></a><h3 class="section">Field Lookup</h3>
<div class="paragraph"> </div>
Lemma: If <span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">v</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" type="var">T</span></span> and <span class="inlinecode"><span class="id" type="var">Tlookup</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">T</span></span> returns <span class="inlinecode"><span class="id" type="var">Some</span></span> <span class="inlinecode"><span class="id" type="var">Ti</span></span>,
then <span class="inlinecode"><span class="id" type="var">tlookup</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">v</span></span> returns <span class="inlinecode"><span class="id" type="var">Some</span></span> <span class="inlinecode"><span class="id" type="var">ti</span></span> for some term <span class="inlinecode"><span class="id" type="var">ti</span></span> such
that <span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">ti</span></span> <span class="inlinecode">∈</span> <span class="inlinecode"><span class="id" type="var">Ti</span></span>.
<div class="paragraph"> </div>
Proof: By induction on the typing derivation <span class="inlinecode"><span class="id" type="var">Htyp</span></span>. Since
<span class="inlinecode"><span class="id" type="var">Tlookup</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">T</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">Some</span></span> <span class="inlinecode"><span class="id" type="var">Ti</span></span>, <span class="inlinecode"><span class="id" type="var">T</span></span> must be a record type, this and
the fact that <span class="inlinecode"><span class="id" type="var">v</span></span> is a value eliminate most cases by inspection,
leaving only the <span class="inlinecode"><span class="id" type="var">T_RCons</span></span> case.
<div class="paragraph"> </div>
If the last step in the typing derivation is by <span class="inlinecode"><span class="id" type="var">T_RCons</span></span>, then
<span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span> and <span class="inlinecode"><span class="id" type="var">T</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">TRCons</span></span> <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span> <span class="inlinecode"><span class="id" type="var">T</span></span> <span class="inlinecode"><span class="id" type="var">Tr</span></span> for some <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span>,
<span class="inlinecode"><span class="id" type="var">t</span></span>, <span class="inlinecode"><span class="id" type="var">tr</span></span>, <span class="inlinecode"><span class="id" type="var">T</span></span> and <span class="inlinecode"><span class="id" type="var">Tr</span></span>.
<div class="paragraph"> </div>
This leaves two possiblities to consider - either <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">i</span></span> or
not.
<div class="paragraph"> </div>
<ul class="doclist">
<li> If <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span>, then since <span class="inlinecode"><span class="id" type="var">Tlookup</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode">(<span class="id" type="var">TRCons</span></span> <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span> <span class="inlinecode"><span class="id" type="var">T</span></span> <span class="inlinecode"><span class="id" type="var">Tr</span>)</span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">Some</span></span>
<span class="inlinecode"><span class="id" type="var">Ti</span></span> we have <span class="inlinecode"><span class="id" type="var">T</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">Ti</span></span>. It follows that <span class="inlinecode"><span class="id" type="var">t</span></span> itself satisfies
the theorem.
<div class="paragraph"> </div>
</li>
<li> On the other hand, suppose <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode">≠</span> <span class="inlinecode"><span class="id" type="var">i<sub>0</sub></span></span>. Then
<div class="paragraph"> </div>
<div class="code code-tight">
<span class="id" type="var">Tlookup</span> <span class="id" type="var">i</span> <span class="id" type="var">T</span> = <span class="id" type="var">Tlookup</span> <span class="id" type="var">i</span> <span class="id" type="var">Tr</span>
<div class="paragraph"> </div>
</div>
and
<div class="paragraph"> </div>
<div class="code code-tight">
<span class="id" type="var">tlookup</span> <span class="id" type="var">i</span> <span class="id" type="var">t</span> = <span class="id" type="var">tlookup</span> <span class="id" type="var">i</span> <span class="id" type="var">tr</span>,
<div class="paragraph"> </div>
</div>
so the result follows from the induction hypothesis. <font size=-2 color="rgb(80%,80%,100%)">☐</font>
</li>
</ul>
<div class="paragraph"> </div>
Here is the formal statement:
</div>
<div class="code code-tight">
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.lookup_field_in_value"><span class="id" type="lemma">lookup_field_in_value</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">v</span> <span class="id" type="var">T</span> <span class="id" type="var">i</span> <span class="id" type="var">Ti</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#v"><span class="id" type="variable">v</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#v"><span class="id" type="variable">v</span></a> ∈ <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.Tlookup"><span class="id" type="definition">Tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#Ti"><span class="id" type="variable">Ti</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: arial;">∃</span><span class="id" type="var">ti</span>, <a class="idref" href="Records.html#STLCExtendedRecords.tlookup"><span class="id" type="definition">tlookup</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#v"><span class="id" type="variable">v</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#ti"><span class="id" type="variable">ti</span></a> <span style="font-family: arial;">∧</span> <a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#ti"><span class="id" type="variable">ti</span></a> ∈ <a class="idref" href="Records.html#Ti"><span class="id" type="variable">Ti</span></a>.<br/>
<div class="togglescript" id="proofcontrol4" onclick="toggleDisplay('proof4');toggleDisplay('proofcontrol4')"><span class="show"></span></div>
<div class="proofscript" id="proof4" onclick="toggleDisplay('proof4');toggleDisplay('proofcontrol4')">
<span class="id" type="keyword">Proof</span> <span class="id" type="keyword">with</span> <span class="id" type="tactic">eauto</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">v</span> <span class="id" type="var">T</span> <span class="id" type="var">i</span> <span class="id" type="var">Ti</span> <span class="id" type="var">Hval</span> <span class="id" type="var">Htyp</span> <span class="id" type="var">Hget</span>.<br/>
<span class="id" type="var">remember</span> (@<a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a>) <span class="id" type="keyword">as</span> <span style="font-family: serif; font-size:85%;">Γ</span>.<br/>
<span class="id" type="tactic">induction</span> <span class="id" type="var">Htyp</span>; <span class="id" type="tactic">subst</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">solve_by_invert</span>...<br/>
- <span class="comment">(* T_RCons *)</span><br/>
<span class="id" type="tactic">simpl</span> <span class="id" type="keyword">in</span> <span class="id" type="var">Hget</span>. <span class="id" type="tactic">simpl</span>. <span class="id" type="tactic">destruct</span> (<a class="idref" href="Maps.html#beq_id"><span class="id" type="definition">beq_id</span></a> <span class="id" type="var">i</span> <span class="id" type="var">i<sub>0</sub></span>).<br/>
+ <span class="comment">(* i is first *)</span><br/>
<span class="id" type="tactic">simpl</span>. <span class="id" type="tactic">inversion</span> <span class="id" type="var">Hget</span>. <span class="id" type="tactic">subst</span>.<br/>
<span style="font-family: arial;">∃</span><span class="id" type="var">t</span>...<br/>
+ <span class="comment">(* get tail *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHtyp2</span> <span class="id" type="keyword">as</span> [<span class="id" type="var">vi</span> [<span class="id" type="var">Hgeti</span> <span class="id" type="var">Htypi</span>]]...<br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">Hval</span>... <span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
</div>
<div class="doc">
<a name="lab703"></a><h3 class="section">Progress</h3>
</div>
<div class="code code-space">
<br/>
<span class="id" type="keyword">Theorem</span> <a name="STLCExtendedRecords.progress"><span class="id" type="lemma">progress</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">t</span> <span class="id" type="var">T</span>,<br/>
<a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#STLCExtendedRecords.value"><span class="id" type="inductive">value</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <span style="font-family: arial;">∨</span> <span style="font-family: arial;">∃</span><span class="id" type="var">t'</span>, <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <span style="font-family: arial;">⇒</span> <a class="idref" href="Records.html#t'"><span class="id" type="variable">t'</span></a>.<br/>
<div class="togglescript" id="proofcontrol5" onclick="toggleDisplay('proof5');toggleDisplay('proofcontrol5')"><span class="show"></span></div>
<div class="proofscript" id="proof5" onclick="toggleDisplay('proof5');toggleDisplay('proofcontrol5')">
<span class="id" type="keyword">Proof</span> <span class="id" type="keyword">with</span> <span class="id" type="tactic">eauto</span>.<br/>
<span class="comment">(* Theorem: Suppose empty |- t : T. Then either<br/>
1. t is a value, or<br/>
2. t ==> t' for some t'.<br/>
Proof: By induction on the given typing derivation. *)</span><br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span> <span class="id" type="var">Ht</span>.<br/>
<span class="id" type="var">remember</span> (@<a class="idref" href="Maps.html#empty"><span class="id" type="definition">empty</span></a> <a class="idref" href="Records.html#STLCExtendedRecords.ty"><span class="id" type="inductive">ty</span></a>) <span class="id" type="keyword">as</span> <span style="font-family: serif; font-size:85%;">Γ</span>.<br/>
<span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span class="id" type="var">HeqGamma</span>.<br/>
<span class="id" type="tactic">induction</span> <span class="id" type="var">Ht</span>; <span class="id" type="tactic">intros</span> <span class="id" type="var">HeqGamma</span>; <span class="id" type="tactic">subst</span>.<br/>
- <span class="comment">(* T_Var *)</span><br/>
<span class="comment">(* The final rule in the given typing derivation cannot be <br/>
<span class="inlinecode"><span class="id" type="var">T_Var</span></span>, since it can never be the case that <br/>
<span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">x</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" type="var">T</span></span> (since the context is empty). *)</span><br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">H</span>.<br/>
- <span class="comment">(* T_Abs *)</span><br/>
<span class="comment">(* If the <span class="inlinecode"><span class="id" type="var">T_Abs</span></span> rule was the last used, then <br/>
<span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">tabs</span></span> <span class="inlinecode"><span class="id" type="var">x</span></span> <span class="inlinecode"><span class="id" type="var">T<sub>11</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>12</sub></span></span>, which is a value. *)</span><br/>
<span class="id" type="var">left</span>...<br/>
- <span class="comment">(* T_App *)</span><br/>
<span class="comment">(* If the last rule applied was T_App, then <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span>, <br/>
and we know from the form of the rule that<br/>
<span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" type="var">T<sub>1</sub></span></span> <span class="inlinecode"><span style="font-family: arial;">→</span></span> <span class="inlinecode"><span class="id" type="var">T<sub>2</sub></span></span><br/>
<span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" type="var">T<sub>1</sub></span></span><br/>
By the induction hypothesis, each of t<sub>1</sub> and t<sub>2</sub> either is a value<br/>
or can take a step. *)</span><br/>
<span class="id" type="var">right</span>.<br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHt1</span>; <span class="id" type="tactic">subst</span>...<br/>
+ <span class="comment">(* t<sub>1</sub> is a value *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHt2</span>; <span class="id" type="tactic">subst</span>...<br/>
* <span class="comment">(* t<sub>2</sub> is a value *)</span><br/>
<span class="comment">(* If both <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> and <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> are values, then we know that<br/>
<span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">tabs</span></span> <span class="inlinecode"><span class="id" type="var">x</span></span> <span class="inlinecode"><span class="id" type="var">T<sub>11</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>12</sub></span></span>, since abstractions are the only <br/>
values that can have an arrow type. But<br/>
<span class="inlinecode">(<span class="id" type="var">tabs</span></span> <span class="inlinecode"><span class="id" type="var">x</span></span> <span class="inlinecode"><span class="id" type="var">T<sub>11</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>12</sub></span>)</span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode">[<span class="id" type="var">x</span>:=<span class="id" type="var">t<sub>2</sub></span>]<span class="id" type="var">t<sub>12</sub></span></span> by <span class="inlinecode"><span class="id" type="var">ST_AppAbs</span></span>. *)</span><br/>
<span class="id" type="tactic">inversion</span> <span class="id" type="var">H</span>; <span class="id" type="tactic">subst</span>; <span class="id" type="tactic">try</span> <span class="id" type="var">solve_by_invert</span>.<br/>
<span style="font-family: arial;">∃</span>([<span class="id" type="var">x</span>:=<span class="id" type="var">t<sub>2</sub></span>]<span class="id" type="var">t<sub>12</sub></span>)...<br/>
* <span class="comment">(* t<sub>2</sub> steps *)</span><br/>
<span class="comment">(* If <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> is a value and <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub>'</span></span>, then <br/>
<span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub>'</span></span> by <span class="inlinecode"><span class="id" type="var">ST_App2</span></span>. *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">H<sub>0</sub></span> <span class="id" type="keyword">as</span> [<span class="id" type="var">t<sub>2</sub>'</span> <span class="id" type="var">Hstp</span>]. <span style="font-family: arial;">∃</span>(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub>'</span>)...<br/>
+ <span class="comment">(* t<sub>1</sub> steps *)</span><br/>
<span class="comment">(* Finally, If <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>1</sub>'</span></span>, then <span class="inlinecode"><span class="id" type="var">t<sub>1</sub></span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>1</sub>'</span></span> <span class="inlinecode"><span class="id" type="var">t<sub>2</sub></span></span> <br/>
by <span class="inlinecode"><span class="id" type="var">ST_App1</span></span>. *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">H</span> <span class="id" type="keyword">as</span> [<span class="id" type="var">t<sub>1</sub>'</span> <span class="id" type="var">Hstp</span>]. <span style="font-family: arial;">∃</span>(<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <span class="id" type="var">t<sub>1</sub>'</span> <span class="id" type="var">t<sub>2</sub></span>)...<br/>
- <span class="comment">(* T_Proj *)</span><br/>
<span class="comment">(* If the last rule in the given derivation is <span class="inlinecode"><span class="id" type="var">T_Proj</span></span>, then<br/>
<span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">tproj</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> and<br/>
<span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">:</span> <span class="inlinecode">(<span class="id" type="var">TRcd</span></span> <span class="inlinecode"><span class="id" type="var">Tr</span>)</span><br/>
By the IH, <span class="inlinecode"><span class="id" type="var">t</span></span> either is a value or takes a step. *)</span><br/>
<span class="id" type="var">right</span>. <span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHt</span>...<br/>
+ <span class="comment">(* rcd is value *)</span><br/>
<span class="comment">(* If <span class="inlinecode"><span class="id" type="var">t</span></span> is a value, then we may use lemma<br/>
<span class="inlinecode"><span class="id" type="var">lookup_field_in_value</span></span> to show <span class="inlinecode"><span class="id" type="var">tlookup</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">Some</span></span> <span class="inlinecode"><span class="id" type="var">ti</span></span> <br/>
for some <span class="inlinecode"><span class="id" type="var">ti</span></span> which gives us <span class="inlinecode"><span class="id" type="var">tproj</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">ti</span></span> by <br/>
<span class="inlinecode"><span class="id" type="var">ST_ProjRcd</span></span>. *)</span><br/>
<span class="id" type="tactic">destruct</span> (<a class="idref" href="Records.html#STLCExtendedRecords.lookup_field_in_value"><span class="id" type="lemma">lookup_field_in_value</span></a> <span class="id" type="var">_</span> <span class="id" type="var">_</span> <span class="id" type="var">_</span> <span class="id" type="var">_</span> <span class="id" type="var">H<sub>0</sub></span> <span class="id" type="var">Ht</span> <span class="id" type="var">H</span>)<br/>
<span class="id" type="keyword">as</span> [<span class="id" type="var">ti</span> [<span class="id" type="var">Hlkup</span> <span class="id" type="var">_</span>]].<br/>
<span style="font-family: arial;">∃</span><span class="id" type="var">ti</span>...<br/>
+ <span class="comment">(* rcd_steps *)</span><br/>
<span class="comment">(* On the other hand, if <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">t'</span></span>, then <br/>
<span class="inlinecode"><span class="id" type="var">tproj</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">tproj</span></span> <span class="inlinecode"><span class="id" type="var">t'</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> by <span class="inlinecode"><span class="id" type="var">ST_Proj1</span></span>. *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">H<sub>0</sub></span> <span class="id" type="keyword">as</span> [<span class="id" type="var">t'</span> <span class="id" type="var">Hstp</span>]. <span style="font-family: arial;">∃</span>(<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <span class="id" type="var">t'</span> <span class="id" type="var">i</span>)...<br/>
- <span class="comment">(* T_RNil *)</span><br/>
<span class="comment">(* If the last rule in the given derivation is <span class="inlinecode"><span class="id" type="var">T_RNil</span></span>, <br/>
then <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">trnil</span></span>, which is a value. *)</span><br/>
<span class="id" type="var">left</span>...<br/>
- <span class="comment">(* T_RCons *)</span><br/>
<span class="comment">(* If the last rule is <span class="inlinecode"><span class="id" type="var">T_RCons</span></span>, then <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span> and<br/>
<span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" type="var">T</span></span><br/>
<span class="inlinecode"><span class="id" type="var">empty</span></span> <span class="inlinecode"><span style="font-family: arial;">⊢</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span> <span class="inlinecode">:</span> <span class="inlinecode"><span class="id" type="var">Tr</span></span><br/>
By the IH, each of <span class="inlinecode"><span class="id" type="var">t</span></span> and <span class="inlinecode"><span class="id" type="var">tr</span></span> either is a value or can <br/>
take a step. *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHt1</span>...<br/>
+ <span class="comment">(* head is a value *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHt2</span>; <span class="id" type="tactic">try</span> <span class="id" type="tactic">reflexivity</span>.<br/>
* <span class="comment">(* tail is a value *)</span><br/>
<span class="comment">(* If <span class="inlinecode"><span class="id" type="var">t</span></span> and <span class="inlinecode"><span class="id" type="var">tr</span></span> are both values, then <span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span><br/>
is a value as well. *)</span><br/>
<span class="id" type="var">left</span>...<br/>
* <span class="comment">(* tail steps *)</span><br/>
<span class="comment">(* If <span class="inlinecode"><span class="id" type="var">t</span></span> is a value and <span class="inlinecode"><span class="id" type="var">tr</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">tr'</span></span>, then<br/>
<span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">tr'</span></span> by<br/>
<span class="inlinecode"><span class="id" type="var">ST_Rcd_Tail</span></span>. *)</span><br/>
<span class="id" type="var">right</span>. <span class="id" type="tactic">destruct</span> <span class="id" type="var">H<sub>2</sub></span> <span class="id" type="keyword">as</span> [<span class="id" type="var">tr'</span> <span class="id" type="var">Hstp</span>].<br/>
<span style="font-family: arial;">∃</span>(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <span class="id" type="var">i</span> <span class="id" type="var">t</span> <span class="id" type="var">tr'</span>)...<br/>
+ <span class="comment">(* head steps *)</span><br/>
<span class="comment">(* If <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">t'</span></span>, then<br/>
<span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span> <span class="inlinecode"><span style="font-family: arial;">⇒</span></span> <span class="inlinecode"><span class="id" type="var">trcons</span></span> <span class="inlinecode"><span class="id" type="var">i</span></span> <span class="inlinecode"><span class="id" type="var">t'</span></span> <span class="inlinecode"><span class="id" type="var">tr</span></span><br/>
by <span class="inlinecode"><span class="id" type="var">ST_Rcd_Head</span></span>. *)</span><br/>
<span class="id" type="var">right</span>. <span class="id" type="tactic">destruct</span> <span class="id" type="var">H<sub>1</sub></span> <span class="id" type="keyword">as</span> [<span class="id" type="var">t'</span> <span class="id" type="var">Hstp</span>].<br/>
<span style="font-family: arial;">∃</span>(<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <span class="id" type="var">i</span> <span class="id" type="var">t'</span> <span class="id" type="var">tr</span>)... <span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
</div>
<div class="doc">
<a name="lab704"></a><h3 class="section">Context Invariance</h3>
</div>
<div class="code code-space">
<br/>
<span class="id" type="keyword">Inductive</span> <a name="STLCExtendedRecords.appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> : <a class="idref" href="Maps.html#id"><span class="id" type="inductive">id</span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#STLCExtendedRecords.tm"><span class="id" type="inductive">tm</span></a> <span style="font-family: arial;">→</span> <span class="id" type="keyword">Prop</span> :=<br/>
| <a name="STLCExtendedRecords.afi_var"><span class="id" type="constructor">afi_var</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span>,<br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tvar"><span class="id" type="constructor">tvar</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a>)<br/>
| <a name="STLCExtendedRecords.afi_app1"><span class="id" type="constructor">afi_app1</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.afi_app2"><span class="id" type="constructor">afi_app2</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">t<sub>1</sub></span> <span class="id" type="var">t<sub>2</sub></span>,<br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a> <span style="font-family: arial;">→</span> <a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tapp"><span class="id" type="constructor">tapp</span></a> <a class="idref" href="Records.html#t<sub>1</sub>"><span class="id" type="variable">t<sub>1</sub></span></a> <a class="idref" href="Records.html#t<sub>2</sub>"><span class="id" type="variable">t<sub>2</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.afi_abs"><span class="id" type="constructor">afi_abs</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">y</span> <span class="id" type="var">T<sub>11</sub></span> <span class="id" type="var">t<sub>12</sub></span>,<br/>
<a class="idref" href="Records.html#y"><span class="id" type="variable">y</span></a> ≠ <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tabs"><span class="id" type="constructor">tabs</span></a> <a class="idref" href="Records.html#y"><span class="id" type="variable">y</span></a> <a class="idref" href="Records.html#T<sub>11</sub>"><span class="id" type="variable">T<sub>11</sub></span></a> <a class="idref" href="Records.html#t<sub>12</sub>"><span class="id" type="variable">t<sub>12</sub></span></a>)<br/>
| <a name="STLCExtendedRecords.afi_proj"><span class="id" type="constructor">afi_proj</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">t</span> <span class="id" type="var">i</span>,<br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.tproj"><span class="id" type="constructor">tproj</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a>)<br/>
| <a name="STLCExtendedRecords.afi_rhead"><span class="id" type="constructor">afi_rhead</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">i</span> <span class="id" type="var">ti</span> <span class="id" type="var">tr</span>,<br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#ti"><span class="id" type="variable">ti</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#ti"><span class="id" type="variable">ti</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a>)<br/>
| <a name="STLCExtendedRecords.afi_rtail"><span class="id" type="constructor">afi_rtail</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">i</span> <span class="id" type="var">ti</span> <span class="id" type="var">tr</span>,<br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a> <span style="font-family: arial;">→</span><br/>
<a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> (<a class="idref" href="Records.html#STLCExtendedRecords.trcons"><span class="id" type="constructor">trcons</span></a> <a class="idref" href="Records.html#i"><span class="id" type="variable">i</span></a> <a class="idref" href="Records.html#ti"><span class="id" type="variable">ti</span></a> <a class="idref" href="Records.html#tr"><span class="id" type="variable">tr</span></a>).<br/>
<br/>
<span class="id" type="keyword">Hint</span> <span class="id" type="var">Constructors</span> <a class="idref" href="Records.html#appears_free_in"><span class="id" type="inductive">appears_free_in</span></a>.<br/>
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.context_invariance"><span class="id" type="lemma">context_invariance</span></a> : <span style="font-family: arial;">∀</span><span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: serif; font-size:85%;">Γ'</span> <span class="id" type="var">t</span> <span class="id" type="var">S</span>,<br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#S"><span class="id" type="variable">S</span></a> <span style="font-family: arial;">→</span><br/>
(<span style="font-family: arial;">∀</span><span class="id" type="var">x</span>, <a class="idref" href="Records.html#STLCExtendedRecords.appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <span style="font-family: arial;">→</span> <span style="font-family: serif; font-size:85%;">Γ</span> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> = <span style="font-family: serif; font-size:85%;">Γ'</span> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a>) <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ'</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#S"><span class="id" type="variable">S</span></a>.<br/>
<div class="togglescript" id="proofcontrol6" onclick="toggleDisplay('proof6');toggleDisplay('proofcontrol6')"><span class="show"></span></div>
<div class="proofscript" id="proof6" onclick="toggleDisplay('proof6');toggleDisplay('proofcontrol6')">
<span class="id" type="keyword">Proof</span> <span class="id" type="keyword">with</span> <span class="id" type="tactic">eauto</span>.<br/>
<span class="id" type="tactic">intros</span>. <span class="id" type="tactic">generalize</span> <span class="id" type="tactic">dependent</span> <span style="font-family: serif; font-size:85%;">Γ'</span>.<br/>
<span class="id" type="tactic">induction</span> <span class="id" type="var">H</span>;<br/>
<span class="id" type="tactic">intros</span> <span style="font-family: serif; font-size:85%;">Γ'</span> <span class="id" type="var">Heqv</span>...<br/>
- <span class="comment">(* T_Var *)</span><br/>
<span class="id" type="tactic">apply</span> <a class="idref" href="Records.html#STLCExtendedRecords.T_Var"><span class="id" type="constructor">T_Var</span></a>... <span class="id" type="tactic">rewrite</span> <span style="font-family: arial;">←</span> <span class="id" type="var">Heqv</span>...<br/>
- <span class="comment">(* T_Abs *)</span><br/>
<span class="id" type="tactic">apply</span> <a class="idref" href="Records.html#STLCExtendedRecords.T_Abs"><span class="id" type="constructor">T_Abs</span></a>... <span class="id" type="tactic">apply</span> <span class="id" type="var">IHhas_type</span>. <span class="id" type="tactic">intros</span> <span class="id" type="var">y</span> <span class="id" type="var">Hafi</span>.<br/>
<span class="id" type="tactic">unfold</span> <a class="idref" href="Maps.html#update"><span class="id" type="definition">update</span></a>, <a class="idref" href="Maps.html#t_update"><span class="id" type="definition">t_update</span></a>. <span class="id" type="tactic">destruct</span> (<a class="idref" href="Maps.html#beq_idP"><span class="id" type="axiom">beq_idP</span></a> <span class="id" type="var">x</span> <span class="id" type="var">y</span>)...<br/>
- <span class="comment">(* T_App *)</span><br/>
<span class="id" type="tactic">apply</span> <a class="idref" href="Records.html#STLCExtendedRecords.T_App"><span class="id" type="constructor">T_App</span></a> <span class="id" type="keyword">with</span> <span class="id" type="var">T<sub>1</sub></span>...<br/>
- <span class="comment">(* T_RCons *)</span><br/>
<span class="id" type="tactic">apply</span> <a class="idref" href="Records.html#STLCExtendedRecords.T_RCons"><span class="id" type="constructor">T_RCons</span></a>... <span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
<span class="id" type="keyword">Lemma</span> <a name="STLCExtendedRecords.free_in_context"><span class="id" type="lemma">free_in_context</span></a> : <span style="font-family: arial;">∀</span><span class="id" type="var">x</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span> <span style="font-family: serif; font-size:85%;">Γ</span>,<br/>
<a class="idref" href="Records.html#STLCExtendedRecords.appears_free_in"><span class="id" type="inductive">appears_free_in</span></a> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: serif; font-size:85%;">Γ</span> <span style="font-family: arial;">⊢</span> <a class="idref" href="Records.html#t"><span class="id" type="variable">t</span></a> ∈ <a class="idref" href="Records.html#T"><span class="id" type="variable">T</span></a> <span style="font-family: arial;">→</span><br/>
<span style="font-family: arial;">∃</span><span class="id" type="var">T'</span>, <span style="font-family: serif; font-size:85%;">Γ</span> <a class="idref" href="Records.html#x"><span class="id" type="variable">x</span></a> = <a class="idref" href="http://coq.inria.fr/library/Coq.Init.Datatypes.html#Some"><span class="id" type="constructor">Some</span></a> <a class="idref" href="Records.html#T'"><span class="id" type="variable">T'</span></a>.<br/>
<div class="togglescript" id="proofcontrol7" onclick="toggleDisplay('proof7');toggleDisplay('proofcontrol7')"><span class="show"></span></div>
<div class="proofscript" id="proof7" onclick="toggleDisplay('proof7');toggleDisplay('proofcontrol7')">
<span class="id" type="keyword">Proof</span> <span class="id" type="keyword">with</span> <span class="id" type="tactic">eauto</span>.<br/>
<span class="id" type="tactic">intros</span> <span class="id" type="var">x</span> <span class="id" type="var">t</span> <span class="id" type="var">T</span> <span style="font-family: serif; font-size:85%;">Γ</span> <span class="id" type="var">Hafi</span> <span class="id" type="var">Htyp</span>.<br/>
<span class="id" type="tactic">induction</span> <span class="id" type="var">Htyp</span>; <span class="id" type="tactic">inversion</span> <span class="id" type="var">Hafi</span>; <span class="id" type="tactic">subst</span>...<br/>
- <span class="comment">(* T_Abs *)</span><br/>
<span class="id" type="tactic">destruct</span> <span class="id" type="var">IHHtyp</span> <span class="id" type="keyword">as</span> [<span class="id" type="var">T'</span> <span class="id" type="var">Hctx</span>]... <span style="font-family: arial;">∃</span><span class="id" type="var">T'</span>.<br/>
<span class="id" type="tactic">unfold</span> <a class="idref" href="Maps.html#update"><span class="id" type="definition">update</span></a>, <a class="idref" href="Maps.html#t_update"><span class="id" type="definition">t_update</span></a> <span class="id" type="keyword">in</span> <span class="id" type="var">Hctx</span>.<br/>
<span class="id" type="tactic">rewrite</span> <a class="idref" href="Maps.html#false_beq_id"><span class="id" type="lemma">false_beq_id</span></a> <span class="id" type="keyword">in</span> <span class="id" type="var">Hctx</span>...<br/>
<span class="id" type="keyword">Qed</span>.<br/>
</div>
<br/>
</div>
<div class="doc">
<a name="lab705"></a><h3 class="section">Preservation</h3>
</div>
<div class="code code-space">
<br/>