@@ -170,18 +170,19 @@ We next formalize the syntax of the STLC.
170170> infixr 7 #
171171
172172> data Tm : Type where
173- > Tvar : String -> Tm
173+ > Tvar : Id -> Tm
174174> (#) : Tm -> Tm -> Tm
175- > Tabs : String -> Ty -> Tm -> Tm
175+ > Tabs : Id -> Ty -> Tm -> Tm
176176> Ttrue : Tm
177177> Tfalse : Tm
178178> Tif : Tm -> Tm -> Tm -> Tm
179179
180- > syntax " (" " \\ " [p] " :" [q] " ." [r] " )" = Tabs " p" q r
180+ > syntax " (" " \\ " [p] " :" [q] " ." [r] " )" = Tabs ( MkId " p" ) q r
181181
182182> syntax " lif" [c] " then" [p] " else" [n] = Tif c p n
183183
184- > syntax " &" [p] = Tvar " p"
184+ > var : String -> Tm
185+ > var s = Tvar (MkId s)
185186
186187Note that an abstraction `\ x : T.t` (formally, `tabs x T t`) is
187188always annotated with the type `T` of its : parameter, in contrast
@@ -194,27 +195,27 @@ Some examples...
194195`idB = \ x : Bool . x`
195196
196197> idB : Tm
197- > idB = (\ x : TBool . &x )
198+ > idB = (\ x : TBool . var "x" )
198199
199200`idBB = \ x : Bool -> Bool . x`
200201
201202> idBB : Tm
202- > idBB = (\ x : (TBool :=> TBool) . &x )
203+ > idBB = (\ x : (TBool :=> TBool) . var "x" )
203204
204205`idBBBB = \ x : (Bool -> Bool ) -> (Bool -> Bool ). x`
205206
206207> idBBBB : Tm
207- > idBBBB = (\ x : ((TBool :=> TBool) :=> (TBool :=> TBool)). &x )
208+ > idBBBB = (\ x : ((TBool :=> TBool) :=> (TBool :=> TBool)). var "x" )
208209
209210`k = \ x : Bool . \y:Bool . x`
210211
211212> k : Tm
212- > k = (\ x : TBool . (\y : TBool . &x ))
213+ > k = (\ x : TBool . (\y : TBool . var "x" ))
213214
214215`notB = \ x : Bool . if x then false else true`
215216
216217> notB : Tm
217- > notB = (\ x : TBool . (lif &x then Tfalse else Ttrue))
218+ > notB = (\ x : TBool . (lif (var "x") then Tfalse else Ttrue))
218219
219220=== Operational Semantics
220221
@@ -260,7 +261,7 @@ function is actually applied to an argument. We also make the
260261second choice here.
261262
262263> 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)
264265> V_true : Value Ttrue
265266> V_false : Value Tfalse
266267
@@ -345,15 +346,15 @@ Here is the definition, informally...
345346
346347... and formally :
347348
348- > subst : String -> Tm -> Tm -> Tm
349+ > subst : Id -> Tm -> Tm -> Tm
349350> subst x s (Tvar x') =
350351> case decEq x x' of
351- > Yes _ => s
352- > No _ => ( Tvar x')
352+ > Yes => s
353+ > No _ => Tvar x'
353354> 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
357358> subst x s (t1 # t2) = subst x s t1 # subst x s t2
358359> subst x s Ttrue = Ttrue
359360> subst x s Tfalse = Tfalse
@@ -397,7 +398,7 @@ one of the constructors; your job is to fill in the rest of the
397398constructors and prove that the relation you've defined coincides
398399with the function given above.
399400
400- > data Substi : (s :Tm) -> (x :String ) -> Tm -> Tm -> Type where
401+ > data Substi : (s :Tm) -> (x :Id ) -> Tm -> Tm -> Type where
401402> S_True : Substi s x Ttrue Ttrue
402403> S_False : Substi s x Tfalse Tfalse
403404> 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.
409410> S_Abs2 : Substi s x (Tabs y ty t) (Tabs y ty t)
410411
411412
412- > substi_correct : (s :Tm) -> (x : String ) -> (t : Tm) -> (t' : Tm) ->
413+ > substi_correct : (s :Tm) -> (x : Id ) -> (t : Tm) -> (t' : Tm) ->
413414> (([ x := s ] t) = t') <-> Substi s x t t'
414415> substi_correct s x t t' = ? substi_correct_rhs1
415416
@@ -482,9 +483,9 @@ Formally:
482483> (->> ) = Step
483484>
484485> 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} ->
486487> Value v2 ->
487- > (Tabs x ty t12) # v2 -> > [ x := v2] t12
488+ > (Tabs x ty t12) # v2 -> > subst x v2 t12
488489> ST_App1 : {t1, t1', t2: Tm} ->
489490> t1 -> > t1' ->
490491> t1 # t2 -> > t1' # t2
@@ -515,8 +516,7 @@ Example:
515516 idBB idB ->>* idB
516517
517518> 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
520520
521521Example :
522522
@@ -675,11 +675,11 @@ We can read the three-place relation `Gamma |- t ::T` as:
675675> syntax [context] " |- " [t] " :: " [T] " . " = Has_type context t T
676676
677677> 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 ->
680680> 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 . ->
683683> Gamma |- (Tabs x T11 t12) :: (T11 :=> T12) .
684684> T_App : {Gamma: Context} -> {T11, T12: Ty} -> {t1, t2 : Tm} ->
685685> Gamma |- t1 :: (T11 :=> T12). ->
@@ -697,7 +697,7 @@ We can read the three-place relation `Gamma |- t ::T` as:
697697
698698==== Examples
699699
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) .
701701> typing_example_1 = T_Abs (T_Var Refl)
702702
703703
@@ -709,9 +709,9 @@ Another example:
709709```
710710
711711> 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" ))) ::
715715> (TBool :=> (TBool :=> TBool) :=> TBool) .
716716> typing_example_2 =
717717> 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:
729729
730730> typing_example_3 :
731731> (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 . )
736736> typing_example_3 = ?typing_example_3_rhs
737737
738738$\square$
@@ -753,9 +753,9 @@ to the term `\x:Bool. \y:Bool, x y` -- i.e.,
753753> typing_nonexample_1 :
754754> Not (T : Ty **
755755> 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 . )
759759> typing_nonexample_1 = forallToExistence
760760> (\ a , (T_Abs (T_Abs (T_App (T_Var Refl)(T_Var Refl)))) impossible)
761761
@@ -770,8 +770,8 @@ Another nonexample:
770770> typing_nonexample_3 :
771771> Not (s : Ty ** t : Ty **
772772> empty |-
773- > (Tabs " x" s
774- > (Tvar " x" # Tvar " x" )) :: t . )
773+ > (Tabs (MkId " x" ) s
774+ > (Tvar (MkId " x" ) # Tvar (MkId " x" ) )) :: t . )
775775> typing_nonexample_3 = ?typing_nonexample_3_rhs
776776
777777$\square$
0 commit comments