Lambda.agda 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module Lambda where
  2. open import Prelude
  3. -- Simply typed λ-calculus
  4. infixr 70 _⟶_
  5. data Type : Set where
  6. ι : Type
  7. _⟶_ : Type -> Type -> Type
  8. Ctx : Set
  9. Ctx = List Type
  10. infixl 80 _•_
  11. infix 20 ƛ_
  12. data Term : Ctx -> Type -> Set where
  13. vz : forall {Γ τ } -> Term (Γ , τ) τ
  14. wk : forall {Γ σ τ} -> Term Γ τ -> Term (Γ , σ) τ
  15. _•_ : forall {Γ σ τ} -> Term Γ (σ ⟶ τ) -> Term Γ σ -> Term Γ τ
  16. ƛ_ : forall {Γ σ τ} -> Term (Γ , σ) τ -> Term Γ (σ ⟶ τ)
  17. Terms : Ctx -> Ctx -> Set
  18. Terms Γ Δ = All (Term Γ) Δ
  19. infixl 60 _◄_
  20. infixr 70 _⇒_
  21. _⇒_ : Ctx -> Type -> Type
  22. ε ⇒ τ = τ
  23. (Δ , σ) ⇒ τ = Δ ⇒ σ ⟶ τ
  24. infixl 80 _•ˢ_
  25. _•ˢ_ : {Γ Δ : Ctx}{τ : Type} -> Term Γ (Δ ⇒ τ) -> Terms Γ Δ -> Term Γ τ
  26. t •ˢ ∅ = t
  27. t •ˢ (us ◄ u) = t •ˢ us • u
  28. Var : Ctx -> Type -> Set
  29. Var Γ τ = τ ∈ Γ
  30. var : forall {Γ τ} -> Var Γ τ -> Term Γ τ
  31. var hd = vz
  32. var (tl x) = wk (var x)
  33. vzero : forall {Γ τ} -> Var (Γ , τ) τ
  34. vzero = hd
  35. vsuc : forall {Γ σ τ} -> Var Γ τ -> Var (Γ , σ) τ
  36. vsuc = tl