Skip to content

Commit f0b3f35

Browse files
committed
Added part of progress proof.
1 parent cf20302 commit f0b3f35

File tree

1 file changed

+50
-59
lines changed

1 file changed

+50
-59
lines changed

src/Types.lidr

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Idris!).
2828
== Typed Arithmetic Expressions
2929

3030
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.
3838

3939
The language definition is completely routine.
4040

@@ -237,11 +237,11 @@ or boolean) of their final results.
237237
> TNat : Ty
238238

239239
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.
245245

246246
\[
247247
\begin{prooftree}
@@ -367,66 +367,57 @@ that well-typed normal forms are not stuck -- or conversely, if a
367367
term is well typed, then either it is a value or it can take at
368368
least one step. We call this _progress_.
369369

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')
372371

372+
==== Exercise: 3 stars (finish_progress)
373373

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
377375
you understand the parts we've given of the informal proof in the
378376
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.)
397378

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
400389

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)
403391

404-
(** _Proof_: By induction on a derivation of `|- t \in T`.
392+
Complete the corresponding informal proof:
405393

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`.
410398

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'`.
418403

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`.
421414

422415
- (* FILL IN HERE *)
423-
*)
424-
(** `` *)
425416

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.
430421

431422
<!--
432423

0 commit comments

Comments
 (0)