WellTyped.lagda 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. %include agda.fmt
  2. \subsection{Typing rules}
  3. \label{well-typed}
  4. \AgdaHide{
  5. \begin{code}
  6. module Issue854.WellTyped where
  7. open import Function hiding (_∋_)
  8. open import Data.Fin
  9. open import Data.Product
  10. open import Data.List
  11. open import Data.List.Relation.Unary.Any as Any
  12. open import Data.List.Relation.Binary.Pointwise
  13. open import Data.List.Relation.Binary.Subset.Propositional
  14. open import Data.List.Membership.Propositional
  15. open import Issue854.Terms
  16. open import Issue854.Types
  17. open import Issue854.Context as Ctx hiding (Rel; index)
  18. infix 1 _⊢^v_∶_
  19. infix 1 _⊢^c_∶_
  20. infix 1 _⊢^cs_∶_
  21. infixl 3 _·_
  22. \end{code}
  23. }
  24. \begin{code}
  25. mutual
  26. data _⊢^v_∶_ (Γ : Ctx) : VTerm → VType → Set where
  27. var : ∀ {V} → (m : Γ ∋ V) →
  28. -----------------------
  29. Γ ⊢^v var (toℕ (Ctx.index m)) ∶ V
  30. con : ∀ {Δ P A p k} → (m : (P , A) ∈ Δ) → Γ ⊢^v p ∶ P →
  31. Γ ▻ A ⊢^v k ∶ μ Δ →
  32. -------------------------------
  33. Γ ⊢^v con (toℕ (index m)) p ∶ μ Δ
  34. thunk : ∀ {Σ V c} → Γ ⊢^c c ∶ Σ ⋆ V →
  35. -------------------
  36. Γ ⊢^v thunk c ∶ ⁅ Σ ⋆ V ⁆
  37. ⟨⟩ : ------------
  38. Γ ⊢^v ⟨⟩ ∶ 𝟙
  39. _,_ : ∀ {U V u v} → Γ ⊢^v u ∶ U → Γ ⊢^v v ∶ V →
  40. -------------------------
  41. Γ ⊢^v u , v ∶ U ⊗ V
  42. 𝟘-elim : ∀ {V v} → Γ ⊢^v v ∶ 𝟘 →
  43. -------------
  44. Γ ⊢^v 𝟘-elim v ∶ V
  45. ι₁ : ∀ {U V u} → Γ ⊢^v u ∶ U →
  46. -------------
  47. Γ ⊢^v ι₁ u ∶ U ⊕ V
  48. ι₂ : ∀ {U V v} → Γ ⊢^v v ∶ V →
  49. -------------
  50. Γ ⊢^v ι₂ v ∶ U ⊕ V
  51. -- Pointwise version of the computation judgement.
  52. _⊢^cs_∶_ : Ctx → List CTerm → List CType → Set
  53. _⊢^cs_∶_ Γ = Pointwise (_⊢^c_∶_ Γ)
  54. data _⊢^c_∶_ (Γ : Ctx) : CTerm → CType → Set where
  55. return : ∀ {Σ V v} → Γ ⊢^v v ∶ V →
  56. -----------
  57. Γ ⊢^c return v ∶ Σ ⋆ V
  58. _to_ : ∀ {Σ Σ′ Σ″ U V c k} → Γ ⊢^c c ∶ Σ ⋆ U → Γ ▻ U ⊢^c k ∶ Σ′ ⋆ V →
  59. Σ ⊆ Σ″ → Σ′ ⊆ Σ″ →
  60. ---------------------------------
  61. Γ ⊢^c c to k ∶ Σ″ ⋆ V
  62. force : ∀ {C t} → Γ ⊢^v t ∶ ⁅ C ⁆ →
  63. ----------------
  64. Γ ⊢^c force t ∶ C
  65. let′_be_ : ∀ {V C v k} → Γ ⊢^v v ∶ V → Γ ▻ V ⊢^c k ∶ C →
  66. -----------------------------
  67. Γ ⊢^c let′ v be k ∶ C
  68. ⟨⟩ : -------------
  69. Γ ⊢^c ⟨⟩ ∶ ⊤′
  70. split : ∀ {U V C p k} → Γ ⊢^v p ∶ U ⊗ V → Γ ▻ U ▻ V ⊢^c k ∶ C →
  71. -------------------------------------
  72. Γ ⊢^c split p k ∶ C
  73. π₁ : ∀ {B C p} → Γ ⊢^c p ∶ B & C →
  74. --------------------
  75. Γ ⊢^c π₁ p ∶ B
  76. π₂ : ∀ {B C p} → Γ ⊢^c p ∶ B & C →
  77. --------------------
  78. Γ ⊢^c π₂ p ∶ C
  79. _,_ : ∀ {B C b c} → Γ ⊢^c b ∶ B → Γ ⊢^c c ∶ C →
  80. -------------------------
  81. Γ ⊢^c b , c ∶ B & C
  82. ƛ_ : ∀ {V C b} → Γ ▻ V ⊢^c b ∶ C →
  83. ---------------
  84. Γ ⊢^c ƛ b ∶ V ⇒ C
  85. _·_ : ∀ {V C f a} → Γ ⊢^c f ∶ V ⇒ C → Γ ⊢^v a ∶ V →
  86. -----------------------------
  87. Γ ⊢^c f · a ∶ C
  88. op : ∀ {Σ P A} → (m : (P , A) ∈ Σ) →
  89. -----------------
  90. Γ ⊢^c op (toℕ (Any.index m)) ∶ P ⇒ Σ ⋆ A
  91. iter : ∀ {Δ C φ x} → Γ ⊢^cs φ ∶ Alg Δ C → Γ ⊢^v x ∶ μ Δ →
  92. --------------------------------------
  93. Γ ⊢^c iter φ x ∶ C
  94. run : ∀ {Σ Σ′ Σ″ Σ‴ I U V φ u} → Γ ⊢^cs φ ∶ PHomo Σ′ U I Σ″ V →
  95. Γ ⊢^c u ∶ Σ ⋆ U → Σ ⊆ (Σ′ ++ Σ″) → Σ″ ⊆ Σ‴ →
  96. ---------------------------------------
  97. Γ ⊢^c run φ u ∶ I ⇒ Σ‴ ⋆ V
  98. \end{code}