Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. module Coquand2002a where
  2.  
  3. open import Data.Bool using (Bool ; true ; false ; not ; _∧_ ; T)
  4. open import Data.Empty using (⊥ ; ⊥-elim)
  5. open import Data.Nat using (ℕ)
  6. open import Data.Product using (Σ ; _×_) renaming (_,_ to _∙_)
  7. open import Data.Unit using (⊤ ; tt)
  8. open import Function using (_∘_ ; id)
  9. open import Relation.Binary using (Decidable)
  10. open import Relation.Binary.PropositionalEquality using (_≡_ ; _≢_ ; refl ; sym ; trans ; cong ; cong₂)
  11. open import Relation.Nullary using (¬_ ; yes ; no)
  12. open import Relation.Nullary.Decidable using (⌊_⌋)
  13. open import Relation.Nullary.Negation using () renaming (contradiction to _↯_)
  14.  
  15.  
  16. -- Names.
  17.  
  18. abstract
  19. Name : Set
  20. Name = ℕ
  21.  
  22. _≟_ : Decidable (_≡_ {A = Name})
  23. _≟_ = Data.Nat._≟_
  24.  
  25.  
  26. -- Types.
  27.  
  28. data Ty : Set where
  29. ι : Ty
  30. _⊃_ : Ty → Ty → Ty
  31.  
  32.  
  33. -- Contexts and freshness.
  34.  
  35. mutual
  36. data Cx : Set where
  37. ∅ : Cx
  38. _,_∶_ : (Γ : Cx) (x : Name) {{_ : x ∥ Γ}} → Ty → Cx
  39.  
  40. data _∥_ (x : Name) : Cx → Set where
  41. base : x ∥ ∅
  42. step : ∀ {y Γ B} {{_ : x ∥ Γ}} {{_ : y ∥ Γ}} → x ≢ y → x ∥ (Γ , y ∶ B)
  43.  
  44. _∦_ : Name → Cx → Set
  45. x ∦ Γ = ¬ (x ∥ Γ)
  46.  
  47.  
  48. -- Variable occurrences.
  49.  
  50. data _∶_∈_ (x : Name) (A : Ty) : Cx → Set where
  51. top : ∀ {Γ} {{_ : x ∥ Γ}} → x ∶ A ∈ (Γ , x ∶ A)
  52. pop : ∀ {y B Γ} {{_ : y ∥ Γ}} → x ∶ A ∈ Γ → x ∶ A ∈ (Γ , y ∶ B)
  53.  
  54. _∶_∉_ : Name → Ty → Cx → Set
  55. x ∶ A ∉ Γ = ¬ (x ∶ A ∈ Γ)
  56.  
  57.  
  58. -- Context inclusion.
  59.  
  60. data _⊆_ : Cx → Cx → Set where
  61. done : ∀ {Γ} → ∅ ⊆ Γ
  62. skip : ∀ {x A Γ Γ′} {{_ : x ∥ Γ}} → Γ ⊆ Γ′ → x ∶ A ∈ Γ′ → (Γ , x ∶ A) ⊆ Γ′
  63.  
  64.  
  65. -- Lemmas.
  66.  
  67. ext⊆ : ∀ {Γ Γ′} → (∀ {x A} → x ∶ A ∈ Γ → x ∶ A ∈ Γ′) → Γ ⊆ Γ′
  68. ext⊆ {∅} f = done
  69. ext⊆ {Γ , x ∶ A} f = skip (ext⊆ (f ∘ pop)) (f top)
  70.  
  71. mono∈ : ∀ {x A Γ Γ′} → Γ ⊆ Γ′ → x ∶ A ∈ Γ → x ∶ A ∈ Γ′
  72. mono∈ done ()
  73. mono∈ (skip η i) top = i
  74. mono∈ (skip η i) (pop j) = mono∈ η j
  75.  
  76. refl⊆ : ∀ {Γ} → Γ ⊆ Γ
  77. refl⊆ = ext⊆ id
  78.  
  79. trans⊆ : ∀ {Γ Γ′ Γ″} → Γ ⊆ Γ′ → Γ′ ⊆ Γ″ → Γ ⊆ Γ″
  80. trans⊆ η η′ = ext⊆ (mono∈ η′ ∘ mono∈ η)
  81.  
  82. weak⊆ : ∀ {x A Γ} {{_ : x ∥ Γ}} → Γ ⊆ (Γ , x ∶ A)
  83. weak⊆ = ext⊆ pop
  84.  
  85. ¬i : ∀ {x Γ A} {{_ : x ∥ Γ}} → x ∶ A ∉ Γ
  86. ¬i {x} {{step x≢x}} top = refl ↯ x≢x
  87. ¬i {x} {{step x≢y}} (pop {y} i) with x ≟ y
  88. ¬i {x} {{step x≢x}} (pop {.x} i) | yes refl = refl ↯ x≢x
  89. ¬i {x} {{step x≢y}} (pop {y} i) | no x≢y′ = i ↯ ¬i
  90.  
  91. uniq∈ : ∀ {x Γ A} → (i i′ : x ∶ A ∈ Γ) → i ≡ i′
  92. uniq∈ top top = refl
  93. uniq∈ top (pop i) = ⊥-elim (i ↯ ¬i)
  94. uniq∈ (pop i) top = ⊥-elim (i ↯ ¬i)
  95. uniq∈ (pop i) (pop i′) = cong pop (uniq∈ i i′)
  96.  
  97. uniq⊆ : ∀ {Γ Γ′} → (η η′ : Γ ⊆ Γ′) → η ≡ η′
  98. uniq⊆ done done = refl
  99. uniq⊆ (skip η i) (skip η′ i′) = cong₂ skip (uniq⊆ η η′) (uniq∈ i i′)
  100.  
  101.  
  102. -- Proof trees and substitutions.
  103.  
  104. mutual
  105. data _⊢_ : Cx → Ty → Set where
  106. var : ∀ {A Γ} x → x ∶ A ∈ Γ → Γ ⊢ A
  107. lam : ∀ {A B Γ} x {{_ : x ∥ Γ}} → (Γ , x ∶ A) ⊢ B → Γ ⊢ (A ⊃ B)
  108. app : ∀ {A B Γ} → Γ ⊢ (A ⊃ B) → Γ ⊢ A → Γ ⊢ B
  109. sub : ∀ {A Γ Γ′} → Γ ⊢ A → Γ ⇇ Γ′ → Γ′ ⊢ A
  110.  
  111. data _⇇_ : Cx → Cx → Set where
  112. proj : ∀ {Γ Γ′} → Γ ⊆ Γ′ → Γ ⇇ Γ′
  113. comp : ∀ {Γ Γ′ Γ″} → Γ ⇇ Γ′ → Γ′ ⇇ Γ″ → Γ ⇇ Γ″
  114. [_≔_]_ : ∀ {A Γ Γ′} x {{_ : x ∥ Γ}} → Γ′ ⊢ A → Γ ⇇ Γ′ → (Γ , x ∶ A) ⇇ Γ′
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement