|
|
|
@ -107,7 +107,10 @@ Qed.
|
|
|
|
|
(** Now the other direction. *)
|
|
|
|
|
(* You may find it helpful to introduce intermediate lemmas. *)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(*
|
|
|
|
|
To prove this, we first need to invert the contextual step.
|
|
|
|
|
By induction on the context, we can reconstruct the small-step rule used.
|
|
|
|
|
*)
|
|
|
|
|
Lemma contextual_step_step e1 e2:
|
|
|
|
|
contextual_step e1 e2 → step e1 e2.
|
|
|
|
|
Proof.
|
|
|
|
@ -320,6 +323,12 @@ Inductive src_typed : typing_context → src_expr → type → Prop :=
|
|
|
|
|
where "Γ '⊢S' E : A" := (src_typed Γ E%E A%ty) : FType_scope.
|
|
|
|
|
#[export] Hint Constructors src_typed : core.
|
|
|
|
|
|
|
|
|
|
(*
|
|
|
|
|
This is trivial enough for `eauto` to be able to solve all the cases for us.
|
|
|
|
|
Doing an induction on the source typing rule used, we can infer the structure of `E`,
|
|
|
|
|
the hypothesis needed, and then unfold `erase` to reveal in each case an equivalent
|
|
|
|
|
syntactical typing rule.
|
|
|
|
|
*)
|
|
|
|
|
Lemma type_erasure_correctness Γ E A:
|
|
|
|
|
(Γ ⊢S E : A)%ty → (Γ ⊢ erase E : A)%ty.
|
|
|
|
|
Proof.
|
|
|
|
@ -329,6 +338,14 @@ Qed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(** ** Exercise 4: Unique Typing *)
|
|
|
|
|
(*
|
|
|
|
|
This is a bit of a boring lemma.
|
|
|
|
|
We do induction on the first typing and inversion on the second typing.
|
|
|
|
|
- for integers, this is trivial
|
|
|
|
|
- for variables, since the Γ is shared, by injection we can see that A = B since Γ[x] = Some A = Some B
|
|
|
|
|
- for functions of type `C -> A2` =? `C -> B2`, we need to use the induction hypothesis, which asks us to prove that `Γ |- body : B2` to get that `A2 = B2`
|
|
|
|
|
- for function applications, the induction hypothesis tells us that if `Γ |- e_fn : B1 -> B2`, then `A1 -> A2` = `B1 -> B2`, allowing us to show that `A2 = B2`.
|
|
|
|
|
*)
|
|
|
|
|
Lemma src_typing_unique Γ E A B:
|
|
|
|
|
(Γ ⊢S E : A)%ty → (Γ ⊢S E : B)%ty → A = B.
|
|
|
|
|
Proof.
|
|
|
|
|