Commit c242af05 authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Syntactic typing exercises.

parent fd46e3a2
......@@ -137,3 +137,72 @@ with val_typed : val → ty → Prop :=
RecV f x e : TArr τ1 τ2
where "Γ ⊢ₜ e : τ" := (typed Γ e τ)
and "⊢ᵥ v : τ" := (val_typed v τ).
Lemma Lam_typed Γ x e τ1 τ2 :
(binder_insert x τ1 Γ e : τ2)
Γ (λ: x, e) : TArr τ1 τ2.
Proof.
intros He.
apply Rec_typed.
simpl.
done.
Qed.
Lemma LamV_typed x e τ1 τ2 :
(binder_insert x τ1 e : τ2)
(λ: x, e) : TArr τ1 τ2.
Proof.
intros He.
apply RecV_typed.
simpl.
done.
Qed.
Lemma Let_typed Γ x e1 e2 τ1 τ2 :
(Γ e1 : τ1)
(binder_insert x τ1 Γ e2 : τ2)
Γ (let: x := e1 in e2) : τ2.
Proof.
intros He1 He2.
apply App_typed with τ1.
- by apply Lam_typed.
- done.
Qed.
Lemma Seq_typed Γ e1 e2 τ1 τ2 :
(Γ e1 : τ1)
(Γ e2 : τ2)
Γ (e1;; e2) : τ2.
Proof.
intros He1 He2.
by apply Let_typed with τ1.
Qed.
Lemma Skip_typed Γ :
Γ Skip : ().
Proof.
apply App_typed with ()%ty.
- apply Val_typed, RecV_typed. apply Val_typed, UnitV_typed.
- apply Val_typed, UnitV_typed.
Qed.
Definition swap : val := λ: "l1" "l2",
let: "x" := !"l1" in
"l1" <- !"l2";;
"l2" <- "x".
Lemma swap_typed τ : swap : (ref τ ref τ ()).
Proof.
unfold swap.
apply LamV_typed.
apply Lam_typed.
apply Let_typed with τ.
{ apply Load_typed. by apply Var_typed. }
apply Seq_typed with ()%ty.
{ apply Store_typed with τ.
- by apply Var_typed.
- apply Load_typed. by apply Var_typed. }
apply Store_typed with τ.
- by apply Var_typed.
- by apply Var_typed.
Qed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment