@@ -302,42 +302,42 @@ is always empty.
302
302
\ newline
303
303
\ ]
304
304
305
- > syntax " |-" [p] " . " [q] = Has_type p q
305
+ > syntax " |-" [p] " : " [q] " . " = Has_type p q
306
306
307
307
> data Has_type : Tm -> Ty -> Type where
308
- > T_True : |- Ttrue . TBool
309
- > T_False : |- Tfalse . TBool
308
+ > T_True : |- Ttrue : TBool .
309
+ > T_False : |- Tfalse : TBool .
310
310
> T_If : {t1, t2, t3: Tm} -> {T : Ty} ->
311
- > Has_type t1 TBool ->
312
- > Has_type t2 T ->
313
- > Has_type t3 T ->
314
- > |- (Tif t1 t2 t3) . T
315
- > T_Zero : |- Tzero . TNat
311
+ > |- t1 : TBool . ->
312
+ > |- t2 : T . ->
313
+ > |- t3 : T . ->
314
+ > |- (Tif t1 t2 t3) : T .
315
+ > T_Zero : |- Tzero : TNat .
316
316
> T_Succ : {t1 : Tm} ->
317
- > Has_type t1 TNat ->
318
- > |- (Tsucc t1) . TNat
317
+ > |- t1 : TNat . ->
318
+ > |- (Tsucc t1) : TNat .
319
319
> T_Pred : {t1 : Tm} ->
320
- > Has_type t1 TNat ->
321
- > |- (Tpred t1) . TNat
320
+ > |- t1 : TNat . ->
321
+ > |- (Tpred t1) : TNat .
322
322
> T_Iszero : {t1 : Tm} ->
323
- > Has_type t1 TNat ->
324
- > |- (Tiszero t1) . TBool
323
+ > |- t1 : TNat . ->
324
+ > |- (Tiszero t1) : TBool .
325
325
326
- > has_type_1 : |- (Tif Tfalse Tzero (Tsucc Tzero)) . TNat
326
+ > has_type_1 : |- (Tif Tfalse Tzero (Tsucc Tzero)) : TNat .
327
327
> has_type_1 = T_If (T_False ) (T_Zero ) (T_Succ T_Zero )
328
328
329
329
It's important to realize that the typing relation is a
330
330
_conservative_ (or _static_) approximation : it does not consider
331
331
what happens when the term is reduced -- in particular, it does
332
332
not calculate the type of its normal form.
333
333
334
- > has_type_not : Not (Has_type (Tif Tfalse Tzero Ttrue) TBool)
334
+ > has_type_not : Not ( |- (Tif Tfalse Tzero Ttrue) : TBool . )
335
335
> has_type_not (T_If (T_False ) (T_Zero ) (T_True )) impossible
336
336
337
337
==== Exercise : 1 star, optional (succ_hastype_nat__hastype_nat)
338
338
339
339
> succ_hastype_nat__hastype_nat : {t : Tm} ->
340
- > Has_type (Tsucc t) TNat -> |- t . TNat
340
+ > |- (Tsucc t) : TNat . -> |- t : TNat .
341
341
> succ_hastype_nat__hastype_nat = ? succ_hastype_nat__hastype_nat_rhs
342
342
343
343
$\ square$
@@ -348,21 +348,21 @@ The following two lemmas capture the fundamental property that the
348
348
definitions of boolean and numeric values agree with the typing
349
349
relation.
350
350
351
- > bool_canonical : {t : Tm} -> Has_type t TBool -> Value t -> Bvalue t
351
+ > bool_canonical : {t : Tm} -> |- t : TBool . -> Value t -> Bvalue t
352
352
> bool_canonical {t} ht v =
353
353
> case v of
354
354
> V_bool b => b
355
355
> V_nat n => void (lemma n ht)
356
- > where lemma : {t :Tm} -> Nvalue t -> Not (Has_type t TBool)
356
+ > where lemma : {t :Tm} -> Nvalue t -> Not ( |- t : TBool . )
357
357
> lemma {t= Tzero } n T_Zero impossible
358
358
> lemma {t= Tsucc n'} n (T_Succ n') impossible
359
359
360
- > nat_canonical : {t : Tm} -> Has_type t TNat -> Value t -> Nvalue t
360
+ > nat_canonical : {t : Tm} -> |- t : TNat . -> Value t -> Nvalue t
361
361
> nat_canonical {t} ht v =
362
362
> case v of
363
363
> V_nat n => n
364
364
> V_bool b => void (lemma b ht)
365
- > where lemma : {t :Tm} -> Bvalue t -> Not (Has_type t TNat)
365
+ > where lemma : {t :Tm} -> Bvalue t -> Not ( |- t : TNat . )
366
366
> lemma {t= Ttrue } n T_True impossible
367
367
> lemma {t= Tfalse } n T_False impossible
368
368
@@ -373,7 +373,7 @@ that well-typed normal forms are not stuck -- or conversely, if a
373
373
term is well typed, then either it is a value or it can take at
374
374
least one step. We call this _progress_.
375
375
376
- > progress : {t : Tm} -> {ty : Ty} -> Has_type t ty -> Either (Value t) (t' ** t -> > t')
376
+ > progress : {t : Tm} -> {ty : Ty} -> |- t : ty . -> Either (Value t) (t' ** t -> > t')
377
377
378
378
==== Exercise : 3 stars (finish_progress)
379
379
@@ -434,7 +434,7 @@ The second critical property of typing is that, when a well-typed
434
434
term takes a step, the result is also a well- typed term.
435
435
436
436
> preservation : {t, t': Tm} -> {T : Ty} ->
437
- > Has_type t T -> t -> > t' -> |- t' . T
437
+ > |- t : T . -> t -> > t' -> |- t' : T .
438
438
439
439
==== Exercise : 2 stars (finish_preservation)
440
440
@@ -500,17 +500,17 @@ each one is doing. The set-up for this proof is similar, but
500
500
not exactly the same.
501
501
502
502
> preservation' : {t, t': Tm} -> {T : Ty} ->
503
- > Has_type t T -> t -> > t' -> |- t' . T
503
+ > |- t : T . -> t -> > t' -> |- t' : T .
504
504
> preservation' h1 h2 = ? preservation'_rhs
505
505
506
+ $\ square$
507
+
506
508
The preservation theorem is often called _subject reduction_,
507
509
because it tells us what happens when the " subject" of the typing
508
510
relation is reduced. This terminology comes from thinking of
509
511
typing statements as sentences, where the term is the subject and
510
512
the type is the predicate.
511
513
512
- $\ square$
513
-
514
514
=== Type Soundness
515
515
516
516
Putting progress and preservation together, we see that a
@@ -525,7 +525,7 @@ well-typed term can never reach a stuck state.
525
525
> multistep = Multi Step
526
526
527
527
> soundness : {t, t': Tm} -> {T : Ty} ->
528
- > Has_type t T ->
528
+ > |- t : T . ->
529
529
> t -> >* t' ->
530
530
> Not (stuck t')
531
531
> soundness ht Multi_refl (sl,sr) =
0 commit comments