@@ -28,13 +28,13 @@ Idris!).
28
28
== Typed Arithmetic Expressions
29
29
30
30
To motivate the discussion of type systems, let 's begin as
31
- usual with a tiny toy language. We want it to have the potential
32
- for programs to go wrong because of runtime type errors, so we
33
- need something a tiny bit more complex than the language of
34
- constants and addition that we used in chapter `Smallstep` : a
35
- single kind of data (e. g. , numbers) is too simple, but just two
36
- kinds (numbers and booleans) gives us enough material to tell an
37
- interesting story.
31
+ usual with a tiny toy language. We want it to have the potential
32
+ for programs to go wrong because of runtime type errors, so we
33
+ need something a tiny bit more complex than the language of
34
+ constants and addition that we used in chapter `Smallstep` : a
35
+ single kind of data (e. g. , numbers) is too simple, but just two
36
+ kinds (numbers and booleans) gives us enough material to tell an
37
+ interesting story.
38
38
39
39
The language definition is completely routine.
40
40
@@ -237,11 +237,11 @@ or boolean) of their final results.
237
237
> TNat : Ty
238
238
239
239
In informal notation, the typing relation is often written
240
- `|- t \ in T ` and pronounced " `t` has type `T`." The `|- ` symbol
241
- is called a " turnstile." Below , we're going to see richer typing
242
- relations where one or more additional " context" arguments are
243
- written to the left of the turnstile. For the moment, the context
244
- is always empty.
240
+ `|- t \ in T ` and pronounced " `t` has type `T`." The `|- ` symbol
241
+ is called a " turnstile." Below , we're going to see richer typing
242
+ relations where one or more additional " context" arguments are
243
+ written to the left of the turnstile. For the moment, the context
244
+ is always empty.
245
245
246
246
\ [
247
247
\ begin{prooftree}
@@ -367,66 +367,57 @@ that well-typed normal forms are not stuck -- or conversely, if a
367
367
term is well typed, then either it is a value or it can take at
368
368
least one step. We call this _progress_.
369
369
370
- > progress : {t : Tm} -> {T : Ty} ->
371
- > Either (Value t) (t' ** t -> > t')
370
+ > progress : {t : Tm} -> {ty : Ty} -> Has_type t ty -> Either (Value t) (t' ** t -> > t')
372
371
372
+ ==== Exercise : 3 stars (finish_progress)
373
373
374
- (** **** Exercise : 3 stars (finish_progress) *)
375
-
376
- (** Complete the formal proof of the `progress` property. (Make sure
374
+ Complete the formal proof of the `progress` property. (Make sure
377
375
you understand the parts we've given of the informal proof in the
378
376
following exercise before starting -- this will save you a lot of
379
- time. ) * )
380
- Proof with auto.
381
- intros t T HT .
382
- induction HT ...
383
- (* The cases that were obviously values, like T_True and
384
- T_False , were eliminated immediately by auto * )
385
- - (* T_If * )
386
- right. inversion IHHT1 ; clear IHHT1 .
387
- + (* t1 is a value * )
388
- apply (bool_canonical t1 HT1 ) in H .
389
- inversion H ; subst; clear H .
390
- exists t2...
391
- exists t3...
392
- + (* t1 can take a step * )
393
- inversion H as `t1' H1 `.
394
- exists (tif t1' t2 t3)...
395
- (* FILL IN HERE * ) Admitted .
396
- (** `` * )
377
+ time. )
397
378
398
- (** **** Exercise : 3 stars, advanced (finish_progress_informal) *)
399
- (** Complete the corresponding informal proof : *)
379
+ > progress {t= Tif t1 t2 t3} (T_If h1 h2 h3) =
380
+ > case progress h1 of
381
+ > Left hypL => Right (
382
+ > let h1 = bool_canonical h1 hypL
383
+ > in case t1 of
384
+ > Ttrue => (t2 ** ST_IfTrue )
385
+ > Tfalse => (t3 ** ST_IfFalse )
386
+ > )
387
+ > Right (t' ** hr) => Right ((Tif t' t2 t3) ** ST_If hr)
388
+ > progress t = ? progress_rhs
400
389
401
- (** _Theorem_ : If `|- t \in T`, then either `t` is a value or else
402
- `t ==> t'` for some `t'` . * )
390
+ ==== Exercise : 3 stars, advanced (finish_progress_informal)
403
391
404
- ( ** _Proof_ : By induction on a derivation of `|- t \in T`.
392
+ Complete the corresponding informal proof :
405
393
406
- - If the last rule in the derivation is `T_If` , then `t = if t1
407
- then t2 else t3`, with ` |- t1 \ in Bool `, ` |- t2 \ in T ` and ` |- t3
408
- \ in T ` . By the IH , either `t1` is a value or else `t1` can step
409
- to some `t1' `.
394
+ _Theorem_ : If `|- t \ in T` , then either `t` is a value or else
395
+ `t ==> t'` for some `t'` .
396
+
397
+ _Proof_ : By induction on a derivation of `|- t \in T `.
410
398
411
- - If `t1` is a value, then by the canonical forms lemmas
412
- and the fact that `|- t1 \ in Bool ` we have that `t1`
413
- is a `bvalue` -- i.e., it is either `true` or `false`.
414
- If `t1 = true`, then `t` steps to `t2` by `ST_IfTrue` ,
415
- while if `t1 = false`, then `t` steps to `t3` by
416
- `ST_IfFalse` . Either way, `t` can step, which is what
417
- we wanted to show .
399
+ - If the last rule in the derivation is `T_If` , then `t = if t1
400
+ then t2 else t3`, with `|- t1 \ in Bool `, `|- t2 \ in T ` and `|- t3
401
+ \ in T `. By the IH , either `t1` is a value or else `t1` can step
402
+ to some `t1'` .
418
403
419
- - If `t1` itself can take a step, then , by `ST_If` , so can
420
- `t` .
404
+ - If `t1` is a value, then by the canonical forms lemmas
405
+ and the fact that `|- t1 \ in Bool ` we have that `t1`
406
+ is a `bvalue` -- i.e., it is either `true` or `false`.
407
+ If `t1 = true`, then `t` steps to `t2` by `ST_IfTrue` ,
408
+ while if `t1 = false`, then `t` steps to `t3` by
409
+ `ST_IfFalse` . Either way, `t` can step, which is what
410
+ we wanted to show .
411
+
412
+ - If `t1` itself can take a step, then , by `ST_If` , so can
413
+ `t` .
421
414
422
415
- (* FILL IN HERE * )
423
- * )
424
- (** `` * )
425
416
426
- ( ** This theorem is more interesting than the strong progress theorem
427
- that we saw in the `Smallstep` chapter, where _all_ normal forms
428
- were values. Here a term can be stuck, but only if it is ill
429
- typed. * )
417
+ This theorem is more interesting than the strong progress theorem
418
+ that we saw in the `Smallstep` chapter, where _all_ normal forms
419
+ were values. Here a term can be stuck, but only if it is ill
420
+ typed.
430
421
431
422
<!--
432
423
0 commit comments