diff --git a/src/ProgrammingLanguage/STLC/Simple.lagda.md b/src/ProgrammingLanguage/STLC/Simple.lagda.md index 5aad986f6..28f38fa61 100644 --- a/src/ProgrammingLanguage/STLC/Simple.lagda.md +++ b/src/ProgrammingLanguage/STLC/Simple.lagda.md @@ -3,16 +3,11 @@ open import 1Lab.Type open import 1Lab.Path - -open import Data.Nat - open import Data.Maybe -open import Data.List - open import Data.Bool - +open import Data.List open import Data.Dec - +open import Data.Nat open import Data.Sum ``` @@ -22,6 +17,21 @@ open import Data.Sum module ProgrammingLanguage.STLC.Simple where ``` +# The simply-typed lambda calculus + +The simple-typed lamdba calclus (STLC) is an example of one of the smallest +"useful" typed programming languages. While very simple, and lacking +features that would make it useful for real programming, its small +size makes it very appealing for the demonstration of programming +language formalization. + +This file represents the first in a series, exploring several +different approaches to formalizing various properties of the STLC. +We will start with the most "naive" approach, and build off it to +more advanced approaches. + +First, the types of the STLC: the Unit type, products, and functions. + ```agda data Ty : Type where UU : Ty @@ -30,9 +40,10 @@ data Ty : Type where ``` We model contexts as (snoc) lists of pairs, alongside a partial -index function. We use `∷c`{.Agda} as the "reversed" list constructor. -"Sequels" in this series will use more advanced techniques to avoid -this partiality, but it's not that bad ;) +index function. We use `∷c`{.Agda} as the "reversed" list constructor +to avoid confusion about insertion order. +Sequels to this file will use more advanced techniques to avoid +this partiality, but it's alright for right now. ```agda Con : Type @@ -54,7 +65,7 @@ index (Γ ∷c (n , ty)) k with k ≡? n ... | no _ = index Γ k ``` -We note some minor lemmas around indexing: +We also note some minor lemmas around indexing: ```agda index-immediate : ∀ {Γ n t} → index (Γ ∷c (n , t)) n ≡ just t index-duplicate : ∀ {Γ n k t₁ t₂ ρ} → @@ -64,20 +75,20 @@ index-duplicate : ∀ {Γ n k t₁ t₂ ρ} →
```agda index-immediate {Γ} {n} {t} with n ≡? n -... | yes a = refl -... | no ¬a = absurd (¬a refl) +... | yes n≡n = refl +... | no ¬n≡n = absurd (¬n≡n refl) -index-duplicate {Γ} {n} {k} {t₁} {t₂} {ρ} q with k ≡? n -... | yes a = q -... | no ¬a with k ≡? n -... | yes b = absurd (¬a b) -... | no ¬b = q +index-duplicate {Γ} {n} {k} {t₁} {t₂} {ρ} eq with k ≡? n +... | yes k≡n = eq +... | no ¬k≡n with k ≡? n +... | yes k≡n = absurd (¬k≡n k≡n) +... | no ¬k≡n = eq ```
Then, expressions: we have variables, functions and application, -pairs and projections, and the unit type. +pairs and projections, and the unit. ```agda data Expr : Type where @@ -101,7 +112,8 @@ data Expr : Type where We must then define a relation to assign types to expressions, which -we will notate `Γ ⊢ tm ⦂ ty`{.Agda}: +we will notate `Γ ⊢ tm ⦂ ty`{.Agda}, for "a term $tm$ has type $ty$ +in the context $\Gamma$: