From f9e21d7ecf5312a65c63ef43764556afeb376481 Mon Sep 17 00:00:00 2001 From: wadler Date: Mon, 21 May 2018 14:16:29 -0300 Subject: [PATCH] updated LambdaProp to PCF --- src/LambdaProp.lagda | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/LambdaProp.lagda b/src/LambdaProp.lagda index 00af4fe8..69a712ef 100644 --- a/src/LambdaProp.lagda +++ b/src/LambdaProp.lagda @@ -312,7 +312,6 @@ subst {x = y} (ℕ-E {x = x} ⊢L ⊢M ⊢N) ⊢V with x ≟ y subst {x = y} (Fix {x = x} ⊢M) ⊢V with x ≟ y ... | yes refl = Fix (rename-≡ ⊢M) ... | no x≢y = Fix (subst (rename-≢ x≢y ⊢M) ⊢V) -{- \end{code} @@ -324,20 +323,22 @@ is also a closed term with type `A`. In other words, small-step reduction preserves types. \begin{code} -preservation : ∀ {M N A} → ∅ ⊢ M ⦂ A → M ⟹ N → ∅ ⊢ N ⦂ A -preservation (Ax ()) -preservation (⇒-I ⊢N) () -preservation (⇒-E ⊢L ⊢M) (ξ·₁ L⟹L′) with preservation ⊢L L⟹L′ -... | ⊢L′ = ⇒-E ⊢L′ ⊢M -preservation (⇒-E ⊢L ⊢M) (ξ·₂ valueL M⟹M′) with preservation ⊢M M⟹M′ -... | ⊢M′ = ⇒-E ⊢L ⊢M′ -preservation (⇒-E (⇒-I ⊢N) ⊢V) (βλ· valueV) = subst ⊢N ⊢V -preservation `ℕ-I₁ () -preservation `ℕ-I₂ () -preservation (`ℕ-E ⊢L ⊢M ⊢N) (ξif L⟹L′) with preservation ⊢L L⟹L′ -... | ⊢L′ = `ℕ-E ⊢L′ ⊢M ⊢N -preservation (`ℕ-E `ℕ-I₁ ⊢M ⊢N) βif-true = ⊢M -preservation (`ℕ-E `ℕ-I₂ ⊢M ⊢N) βif-false = ⊢N +preserve : ∀ {M N A} + → ∅ ⊢ M ⦂ A + → M ⟹ N + ---------- + → ∅ ⊢ N ⦂ A +preserve (Ax ()) +preserve (⇒-I ⊢N) () +preserve (⇒-E ⊢L ⊢M) (ξ-·₁ L⟹L′) = ⇒-E (preserve ⊢L L⟹L′) ⊢M +preserve (⇒-E ⊢L ⊢M) (ξ-·₂ VL M⟹M′) = ⇒-E ⊢L (preserve ⊢M M⟹M′) +preserve (⇒-E (⇒-I ⊢N) ⊢V) (β-ƛ· VV) = subst ⊢N ⊢V +preserve ℕ-I₁ () +preserve (ℕ-I₂ ⊢M) (ξ-suc M⟹M′) = ℕ-I₂ (preserve ⊢M M⟹M′) +preserve (ℕ-E ⊢L ⊢M ⊢N) (ξ-case L⟹L′) = ℕ-E (preserve ⊢L L⟹L′) ⊢M ⊢N +preserve (ℕ-E ℕ-I₁ ⊢M ⊢N) β-case-zero = ⊢M +preserve (ℕ-E (ℕ-I₂ ⊢V) ⊢M ⊢N) (β-case-suc VV) = subst ⊢N ⊢V +preserve (Fix ⊢M) (β-μ) = subst ⊢M (Fix ⊢M) \end{code} @@ -357,7 +358,7 @@ The preservation property is sometimes called _subject reduction_. Its opposite is _subject expansion_, which holds if `M ==> N` and `∅ ⊢ N ⦂ A`, then `∅ ⊢ M ⦂ A`. Find two counter-examples to subject expansion, one -with conditionals and one not involving conditionals. +with case expressions and one not involving case expressions. ## Type Soundness @@ -374,18 +375,24 @@ Stuck : Term → Set Stuck M = Normal M × ¬ Value M postulate - Soundness : ∀ {M N A} → ∅ ⊢ M ⦂ A → M ⟹* N → ¬ (Stuck N) + Soundness : ∀ {M N A} + → ∅ ⊢ M ⦂ A + → M ⟹* N + ----------- + → ¬ (Stuck N) \end{code} @@ -527,7 +534,7 @@ Suppose we add the following new rule to the typing relation of the STLC: -------------------- (T_FunnyAbs) - ∅ ⊢ λ[ x ⦂ `ℕ ] N ⦂ `ℕ + ∅ ⊢ ƛ x ⇒ N ⦂ `ℕ Which of the following properties of the STLC remain true in the presence of this rule? For each one, write either @@ -541,6 +548,3 @@ false, give a counterexample. - Preservation -\begin{code} --} -\end{code}