@@ -29,12 +29,6 @@ work to deal with these.
29
29
> % hide Smallstep . (->>* )
30
30
> % hide Types . Has_type
31
31
32
-
33
-
34
-
35
-
36
-
37
-
38
32
=== Overview
39
33
40
34
The STLC is built on some collection of _base types_ :
@@ -199,7 +193,7 @@ Some examples...
199
193
`idB = \ x : Bool . x`
200
194
201
195
> idB : Tm
202
- > idB = (\ x : TBool . &x)
196
+ > idB = (\ x : TBool . &x)
203
197
204
198
`idBB = \ x : Bool -> Bool . x`
205
199
@@ -418,6 +412,7 @@ with the function given above.
418
412
> (([ x := s ] t) = t') <-> Substi s x t t'
419
413
> substi_correct s x t t' = ? substi_correct_rhs1
420
414
415
+ $\ square$
421
416
422
417
== Reduction
423
418
@@ -595,12 +590,11 @@ Proof. normalize. Qed.
595
590
596
591
==== Exercise : 2 stars (step_example5)
597
592
598
- Try to do this one both with and without `normalize` .
599
-
600
593
> step_example5 :
601
594
> (Stlc . idBBBB # Stlc . idBB) # Stlc . idB ->>* Stlc . idB
602
595
> step_example5 = ? step_example5_rhs
603
596
597
+ $\ square$
604
598
605
599
=== Typing
606
600
@@ -617,7 +611,7 @@ what assumptions we should make about the types of its free
617
611
variables.
618
612
619
613
This leads us to a three- place _typing judgment_, informally
620
- written `Gamma |- t \ in T `, where `Gamma` is a
614
+ written `Gamma |- t :: T `, where `Gamma` is a
621
615
" typing context" -- a mapping from variables to their types.
622
616
623
617
Following the usual notation for partial maps, we could write `Gamma
@@ -634,47 +628,47 @@ Following the usual notation for partial maps, we could write `Gamma
634
628
\[
635
629
\b egin{prooftree}
636
630
\hypo{\idr{Gamma x = T}}
637
- \infer1[\idr{T_Var}]{\idr{Gamma |- x \in T}}
631
+ \infer1[\idr{T_Var}]{\idr{Gamma |- x :: T}}
638
632
\end{prooftree}
639
633
\]
640
634
641
635
\[
642
636
\b egin{prooftree}
643
- \hypo{\idr{Gamma & {{ x --> T11 }} |- t12 \in T12}}
644
- \infer1[\idr{T_Abs}]{\idr{Gamma |- \x:T11.t12 \in T11->T12}}
637
+ \hypo{\idr{Gamma & {{ x --> T11 }} |- t12 :: T12}}
638
+ \infer1[\idr{T_Abs}]{\idr{Gamma |- \x:T11.t12 :: T11->T12}}
645
639
\end{prooftree}
646
640
\]
647
641
648
642
\[
649
643
\b egin{prooftree}
650
- \hypo{\idr{Gamma |- t1 \in T11->T12}}
651
- \hypo{\idr{Gamma |- t2 \in T11}}
652
- \infer2[\idr{T_App}]{\idr{Gamma |- t1 t2 \in T12}}
644
+ \hypo{\idr{Gamma |- t1 :: T11->T12}}
645
+ \hypo{\idr{Gamma |- t2 :: T11}}
646
+ \infer2[\idr{T_App}]{\idr{Gamma |- t1 t2 :: T12}}
653
647
\end{prooftree}
654
648
\]
655
649
656
650
\[
657
651
\b egin{prooftree}
658
- \infer0[\idr{T_True}]{\idr{Gamma |- true \in Bool}}
652
+ \infer0[\idr{T_True}]{\idr{Gamma |- true :: Bool}}
659
653
\end{prooftree}
660
654
\]
661
655
662
656
\[
663
657
\b egin{prooftree}
664
- \infer0[\idr{T_False}]{\idr{Gamma |- false \in Bool}}
658
+ \infer0[\idr{T_False}]{\idr{Gamma |- false :: Bool}}
665
659
\end{prooftree}
666
660
\]
667
661
668
662
\[
669
663
\b egin{prooftree}
670
- \hypo{\idr{Gamma |- t1 \in Bool}}
671
- \hypo{\idr{Gamma |- t2 \in T}}
672
- \hypo{\idr{Gamma |- t3 \in T}}
673
- \infer3[\idr{T_If}]{\idr{Gamma |- if t1 then t2 else t3 \in T}}
664
+ \hypo{\idr{Gamma |- t1 :: Bool}}
665
+ \hypo{\idr{Gamma |- t2 :: T}}
666
+ \hypo{\idr{Gamma |- t3 :: T}}
667
+ \infer3[\idr{T_If}]{\idr{Gamma |- if t1 then t2 else t3 :: T}}
674
668
\end{prooftree}
675
669
\]
676
670
677
- We can read the three-place relation `Gamma |- t \in T` as:
671
+ We can read the three-place relation `Gamma |- t :: T` as:
678
672
" under the assumptions in Gamma , the term `t` has the type `T` . " *)
679
673
680
674
> syntax [context] " |- " [t] " :: " [T] " . " = Has_type context t T
@@ -687,7 +681,7 @@ We can read the three-place relation `Gamma |- t \in T` as:
687
681
> (Gamma & {{ (MkId x) ==> T11 }}) |- t12 :: T12 . ->
688
682
> Gamma |- (Tabs x T11 t12) :: (T11 :=> T12) .
689
683
> T_App : {Gamma: Context} -> {T11, T12: Ty} -> {t1, t2 : Tm} ->
690
- > Gamma |- t1 :: (T11 :=> T12) . ->
684
+ > Gamma |- t1 :: (T11 :=> T12). ->
691
685
> Gamma |- t2 :: T11 . ->
692
686
> Gamma |- (t1 # t2) :: T12 .
693
687
> T_True : {Gamma: Context} ->
@@ -710,15 +704,16 @@ Another example:
710
704
711
705
```
712
706
empty |- \x:A. \y:A->A. y (y x)
713
- \in A -> (A->A) -> A.
707
+ :: A -> (A->A) -> A.
714
708
```
715
709
716
710
> typing_example_2 : empty |-
717
711
> (Tabs " x" TBool
718
712
> (Tabs " y" (TBool :=> TBool)
719
713
> (Tvar " y" # Tvar " y" # Tvar " x" ))) ::
720
714
> (TBool :=> (TBool :=> TBool) :=> TBool) .
721
- > typing_example_2 = T_Abs (T_Abs (T_App (T_Var Refl) (T_App (T_Var Refl) (T_Var Refl))))
715
+ > typing_example_2 =
716
+ > T_Abs (T_Abs (T_App (T_Var Refl) (T_App (T_Var Refl) (T_Var Refl))))
722
717
723
718
724
719
==== Exercise: 2 stars (typing_example_3)
@@ -728,59 +723,54 @@ Formally prove the following typing derivation holds:
728
723
```
729
724
empty |- \x:Bool->B. \y:Bool->Bool. \z:Bool.
730
725
y (x z)
731
- \in T.
726
+ :: T.
732
727
```
733
728
734
- > typing_example_3 : (T : Ty **
735
- > empty |-
736
- > (Tabs x (TBool :=> TBool)
737
- > (Tabs y (TBool :=> TBool)
738
- > (Tabs z TBool
739
- > (Tvar y # (Tvar x # Tvar z ))))) :: T . )
729
+ > typing_example_3 :
730
+ > (T : Ty ** empty |-
731
+ > (Tabs " x " (TBool :=> TBool)
732
+ > (Tabs " y " (TBool :=> TBool)
733
+ > (Tabs " z " TBool
734
+ > (Tvar " y " # (Tvar " x " # Tvar " z " ))))) :: T . )
740
735
> typing_example_3 = ?typing_example_3_rhs
741
736
737
+ $\square$
738
+
742
739
We can also show that terms are _not_ typable. For example, let's
743
740
formally check that there is no typing derivation assigning a type
744
741
to the term `\x:Bool. \y:Bool, x y` -- i.e.,
745
742
746
743
```
747
744
~ exists T,
748
- empty |- \x:Bool. \y:Bool, x y \in T.
745
+ empty |- \x:Bool. \y:Bool, x y :: T.
749
746
```
750
747
751
- Example typing_nonexample_1 :
752
- ~ exists T,
753
- empty |-
754
- (tabs x TBool
755
- (tabs y TBool
756
- (tapp (tvar x) (tvar y)))) \in
757
- T.
758
- Proof.
759
- intros Hc. inversion Hc.
760
- (* The `clear` tactic is useful here for tidying away bits of
761
- the context that we're not going to need again. *)
762
- inversion H. subst. clear H.
763
- inversion H5. subst. clear H5.
764
- inversion H4. subst. clear H4.
765
- inversion H2. subst. clear H2.
766
- inversion H5. subst. clear H5.
767
- inversion H1. Qed.
768
-
769
- (** **** Exercise: 3 stars, optional (typing_nonexample_3) *)
770
- (** Another nonexample:
771
-
772
- ~ (exists S, exists T,
773
- empty |- \x:S. x x \in T).
774
- *)
775
-
776
- Example typing_nonexample_3 :
777
- ~ (exists S, exists T,
778
- empty |-
779
- (tabs x S
780
- (tapp (tvar x) (tvar x))) \in
781
- T).
782
- Proof.
783
- (* FILL IN HERE *) Admitted.
784
- (** `` *)
785
-
786
- End STLC.
748
+ > forallToExistence : {X : Type} -> {P: X -> Type} ->
749
+ > ((a : X) -> Not (P a)) -> Not (a : X ** P a)
750
+ > forallToExistence hyp (b ** p2) = hyp b p2
751
+
752
+ > typing_nonexample_1 :
753
+ > Not (T : Ty **
754
+ > empty |-
755
+ > (Tabs " x" TBool
756
+ > (Tabs " y" TBool
757
+ > (Tvar " x" # Tvar y))) :: T . )
758
+ > typing_nonexample_1 = forallToExistence
759
+ > (\ a , (T_Abs (T_Abs (T_App (T_Var Refl)(T_Var Refl)))) impossible)
760
+
761
+ ==== Exercise: 3 stars, optional (typing_nonexample_3)
762
+
763
+ Another nonexample:
764
+
765
+ ``` ~ (exists S, exists T,
766
+ empty |- \x:S. x x ::T).
767
+ ```
768
+
769
+ > typing_nonexample_3 :
770
+ > Not (s : Ty ** t : Ty **
771
+ > empty |-
772
+ > (Tabs " x" s
773
+ > (Tvar " x" # Tvar " x" )) :: t . )
774
+ > typing_nonexample_3 = ?typing_nonexample_3_rhs
775
+
776
+ $\square$
0 commit comments