@@ -170,18 +170,19 @@ We next formalize the syntax of the STLC.
170
170
> infixr 7 #
171
171
172
172
> data Tm : Type where
173
- > Tvar : String -> Tm
173
+ > Tvar : Id -> Tm
174
174
> (#) : Tm -> Tm -> Tm
175
- > Tabs : String -> Ty -> Tm -> Tm
175
+ > Tabs : Id -> Ty -> Tm -> Tm
176
176
> Ttrue : Tm
177
177
> Tfalse : Tm
178
178
> Tif : Tm -> Tm -> Tm -> Tm
179
179
180
- > syntax " (" " \\ " [p] " :" [q] " ." [r] " )" = Tabs " p" q r
180
+ > syntax " (" " \\ " [p] " :" [q] " ." [r] " )" = Tabs ( MkId " p" ) q r
181
181
182
182
> syntax " lif" [c] " then" [p] " else" [n] = Tif c p n
183
183
184
- > syntax " &" [p] = Tvar " p"
184
+ > var : String -> Tm
185
+ > var s = Tvar (MkId s)
185
186
186
187
Note that an abstraction `\ x : T.t` (formally, `tabs x T t`) is
187
188
always annotated with the type `T` of its : parameter, in contrast
@@ -194,27 +195,27 @@ Some examples...
194
195
`idB = \ x : Bool . x`
195
196
196
197
> idB : Tm
197
- > idB = (\ x : TBool . &x )
198
+ > idB = (\ x : TBool . var "x" )
198
199
199
200
`idBB = \ x : Bool -> Bool . x`
200
201
201
202
> idBB : Tm
202
- > idBB = (\ x : (TBool :=> TBool) . &x )
203
+ > idBB = (\ x : (TBool :=> TBool) . var "x" )
203
204
204
205
`idBBBB = \ x : (Bool -> Bool ) -> (Bool -> Bool ). x`
205
206
206
207
> idBBBB : Tm
207
- > idBBBB = (\ x : ((TBool :=> TBool) :=> (TBool :=> TBool)). &x )
208
+ > idBBBB = (\ x : ((TBool :=> TBool) :=> (TBool :=> TBool)). var "x" )
208
209
209
210
`k = \ x : Bool . \y:Bool . x`
210
211
211
212
> k : Tm
212
- > k = (\ x : TBool . (\y : TBool . &x ))
213
+ > k = (\ x : TBool . (\y : TBool . var "x" ))
213
214
214
215
`notB = \ x : Bool . if x then false else true`
215
216
216
217
> notB : Tm
217
- > notB = (\ x : TBool . (lif &x then Tfalse else Ttrue))
218
+ > notB = (\ x : TBool . (lif (var "x") then Tfalse else Ttrue))
218
219
219
220
=== Operational Semantics
220
221
@@ -260,7 +261,7 @@ function is actually applied to an argument. We also make the
260
261
second choice here.
261
262
262
263
> data Value : Tm -> Type where
263
- > V_abs : {x : String } -> {T : Ty} -> {t : Tm} -> Value (Tabs x T t)
264
+ > V_abs : {x : Id } -> {T : Ty} -> {t : Tm} -> Value (Tabs x T t)
264
265
> V_true : Value Ttrue
265
266
> V_false : Value Tfalse
266
267
@@ -345,15 +346,15 @@ Here is the definition, informally...
345
346
346
347
... and formally :
347
348
348
- > subst : String -> Tm -> Tm -> Tm
349
+ > subst : Id -> Tm -> Tm -> Tm
349
350
> subst x s (Tvar x') =
350
351
> case decEq x x' of
351
- > Yes _ => s
352
- > No _ => ( Tvar x')
352
+ > Yes => s
353
+ > No _ => Tvar x'
353
354
> subst x s (Tabs x' ty t1) =
354
- > Tabs x' ty ( case decEq x x' of
355
- > Yes p => t1
356
- > No p => subst x s t1)
355
+ > case decEq x x' of
356
+ > Yes => t1
357
+ > No _ => subst x s t1
357
358
> subst x s (t1 # t2) = subst x s t1 # subst x s t2
358
359
> subst x s Ttrue = Ttrue
359
360
> subst x s Tfalse = Tfalse
@@ -397,7 +398,7 @@ one of the constructors; your job is to fill in the rest of the
397
398
constructors and prove that the relation you've defined coincides
398
399
with the function given above.
399
400
400
- > data Substi : (s :Tm) -> (x :String ) -> Tm -> Tm -> Type where
401
+ > data Substi : (s :Tm) -> (x :Id ) -> Tm -> Tm -> Type where
401
402
> S_True : Substi s x Ttrue Ttrue
402
403
> S_False : Substi s x Tfalse Tfalse
403
404
> S_App : {l', r':Tm} -> Substi s x l l' -> Substi s x r r' -> Substi s x (l # r) (l' # r')
@@ -409,7 +410,7 @@ with the function given above.
409
410
> S_Abs2 : Substi s x (Tabs y ty t) (Tabs y ty t)
410
411
411
412
412
- > substi_correct : (s :Tm) -> (x : String ) -> (t : Tm) -> (t' : Tm) ->
413
+ > substi_correct : (s :Tm) -> (x : Id ) -> (t : Tm) -> (t' : Tm) ->
413
414
> (([ x := s ] t) = t') <-> Substi s x t t'
414
415
> substi_correct s x t t' = ? substi_correct_rhs1
415
416
@@ -482,9 +483,9 @@ Formally:
482
483
> (->> ) = Step
483
484
>
484
485
> data Step : Tm -> Tm -> Type where
485
- > ST_AppAbs : {x : String } -> {ty : Ty} -> {t12 : Tm} -> {v2 : Tm} ->
486
+ > ST_AppAbs : {x : Id } -> {ty : Ty} -> {t12 : Tm} -> {v2 : Tm} ->
486
487
> Value v2 ->
487
- > (Tabs x ty t12) # v2 -> > [ x := v2] t12
488
+ > (Tabs x ty t12) # v2 -> > subst x v2 t12
488
489
> ST_App1 : {t1, t1', t2: Tm} ->
489
490
> t1 -> > t1' ->
490
491
> t1 # t2 -> > t1' # t2
@@ -515,8 +516,7 @@ Example:
515
516
idBB idB ->>* idB
516
517
517
518
> step_example1 : Stlc.idBB # Stlc.idB -> >* Stlc.idB
518
- > step_example1 =
519
- > Multi_step (ST_AppAbs V_abs ) Multi_refl
519
+ > step_example1 = Multi_step (ST_AppAbs V_abs ) Multi_refl -- (ST_AppAbs V_abs) Multi_refl
520
520
521
521
Example :
522
522
@@ -675,11 +675,11 @@ We can read the three-place relation `Gamma |- t ::T` as:
675
675
> syntax [context] " |- " [t] " :: " [T] " . " = Has_type context t T
676
676
677
677
> data Has_type : Context -> Tm -> Ty -> Type where
678
- > T_Var : {Gamma: Context} -> {x: String } -> {T: Ty} ->
679
- > Gamma (MkId x) = Just T ->
678
+ > T_Var : {Gamma: Context} -> {x: Id } -> {T: Ty} ->
679
+ > Gamma x = Just T ->
680
680
> Gamma |- (Tvar x) :: T .
681
- > T_Abs : {Gamma: Context} -> {x: String } -> {T11, T12: Ty} -> {t12 : Tm} ->
682
- > (Gamma & {{ (MkId x) ==> T11 }}) |- t12 :: T12 . ->
681
+ > T_Abs : {Gamma: Context} -> {x: Id } -> {T11, T12: Ty} -> {t12 : Tm} ->
682
+ > (Gamma & {{ x ==> T11 }}) |- t12 :: T12 . ->
683
683
> Gamma |- (Tabs x T11 t12) :: (T11 :=> T12) .
684
684
> T_App : {Gamma: Context} -> {T11, T12: Ty} -> {t1, t2 : Tm} ->
685
685
> Gamma |- t1 :: (T11 :=> T12). ->
@@ -697,7 +697,7 @@ We can read the three-place relation `Gamma |- t ::T` as:
697
697
698
698
==== Examples
699
699
700
- > typing_example_1 : empty |- (Tabs " x" TBool (Tvar " x" )) :: (TBool :=> TBool) .
700
+ > typing_example_1 : empty |- (Tabs (MkId " x" ) TBool (var " x" )) :: (TBool :=> TBool) .
701
701
> typing_example_1 = T_Abs (T_Var Refl)
702
702
703
703
@@ -709,9 +709,9 @@ Another example:
709
709
```
710
710
711
711
> typing_example_2 : empty |-
712
- > (Tabs " x" TBool
713
- > (Tabs " y" (TBool :=> TBool)
714
- > (Tvar " y" # Tvar " y" # Tvar " x" ))) ::
712
+ > (Tabs (MkId " x" ) TBool
713
+ > (Tabs (MkId " y" ) (TBool :=> TBool)
714
+ > (var " y" # var " y" # var " x" ))) ::
715
715
> (TBool :=> (TBool :=> TBool) :=> TBool) .
716
716
> typing_example_2 =
717
717
> T_Abs (T_Abs (T_App (T_Var Refl) (T_App (T_Var Refl) (T_Var Refl))))
@@ -729,10 +729,10 @@ Formally prove the following typing derivation holds:
729
729
730
730
> typing_example_3 :
731
731
> (T : Ty ** empty |-
732
- > (Tabs " x" (TBool :=> TBool)
733
- > (Tabs " y" (TBool :=> TBool)
734
- > (Tabs " z" TBool
735
- > (Tvar " y" # (Tvar " x" # Tvar " z" ))))) :: T . )
732
+ > (Tabs (MkId " x" ) (TBool :=> TBool)
733
+ > (Tabs (MkId " y" ) (TBool :=> TBool)
734
+ > (Tabs (MkId " z" ) TBool
735
+ > (Tvar (MkId " y" ) # (Tvar (MkId " x" ) # Tvar (MkId " z" ) ))))) :: T . )
736
736
> typing_example_3 = ?typing_example_3_rhs
737
737
738
738
$\square$
@@ -753,9 +753,9 @@ to the term `\x:Bool. \y:Bool, x y` -- i.e.,
753
753
> typing_nonexample_1 :
754
754
> Not (T : Ty **
755
755
> empty |-
756
- > (Tabs " x" TBool
757
- > (Tabs " y" TBool
758
- > (Tvar " x" # Tvar y ))) :: T . )
756
+ > (Tabs (MkId " x" ) TBool
757
+ > (Tabs (MkId " y" ) TBool
758
+ > (Tvar (MkId " x" ) # Tvar (MkId y) ))) :: T . )
759
759
> typing_nonexample_1 = forallToExistence
760
760
> (\ a , (T_Abs (T_Abs (T_App (T_Var Refl)(T_Var Refl)))) impossible)
761
761
@@ -770,8 +770,8 @@ Another nonexample:
770
770
> typing_nonexample_3 :
771
771
> Not (s : Ty ** t : Ty **
772
772
> empty |-
773
- > (Tabs " x" s
774
- > (Tvar " x" # Tvar " x" )) :: t . )
773
+ > (Tabs (MkId " x" ) s
774
+ > (Tvar (MkId " x" ) # Tvar (MkId " x" ) )) :: t . )
775
775
> typing_nonexample_3 = ?typing_nonexample_3_rhs
776
776
777
777
$\square$
0 commit comments