WellTypedSemantics.lagda 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. \subsection{The semantics of well-typed terms}
  2. \label{well-typed-semantics}
  3. \AgdaHide{
  4. \begin{code}
  5. {-# OPTIONS --sized-types #-}
  6. module Issue854.WellTypedSemantics where
  7. open import Level using (lower)
  8. open import Function hiding (_∋_)
  9. open import Data.Empty
  10. open import Data.Unit
  11. open import Data.Sum
  12. open import Data.Product
  13. open import Data.List
  14. open import Data.List.Relation.Unary.Any
  15. open import Data.List.Relation.Binary.Pointwise hiding (refl)
  16. open import Data.Container.FreeMonad using (rawMonad; inn)
  17. renaming (_⋆_ to _⋆^C_)
  18. open import Data.W
  19. open import Relation.Binary.PropositionalEquality
  20. open import Category.Monad
  21. open import Data.List.Membership.Propositional
  22. open import Issue854.Types
  23. open import Issue854.Context
  24. open import Issue854.EilenbergMooreAlgebra as EMA
  25. open import Issue854.TypesSemantics
  26. open import Issue854.WellTyped
  27. open import Issue854.Run
  28. open import Issue854.RunCompat
  29. \end{code}
  30. }
  31. \begin{code}
  32. ⟦_⟧^var : ∀ {Γ V} → Γ ∋ V → ⟦ Γ ⟧^Ctx → ⟦ V ⟧^VType
  33. ⟦ zero ⟧^var = proj₂
  34. ⟦ suc m ⟧^var = ⟦ m ⟧^var ∘ proj₁
  35. ⟦_⟧^con : ∀ {Δ P A} → (P , A) ∈ Δ → ⟦ P ⟧^VType →
  36. (⟦ A ⟧^VType → ⟦ μ Δ ⟧^VType) → ⟦ μ Δ ⟧^VType
  37. ⟦ m ⟧^con p k = sup (sh m p , k ∘ ar m p)
  38. ⟦_⟧^op : ∀ {Σ P A} → (P , A) ∈ Σ → (⟦ P ⟧^VType → Σ ⋆^S ⟦ A ⟧^VType)
  39. ⟦ m ⟧^op s = inn (sh m s , (M.return ∘ ar m s))
  40. where
  41. module M = RawMonad rawMonad
  42. mutual
  43. ⟦_⟧^v : ∀ {Γ V v} → Γ ⊢^v v ∶ V → ⟦ Γ ⟧^Ctx → ⟦ V ⟧^VType
  44. ⟦ var m ⟧^v γ = ⟦ m ⟧^var γ
  45. ⟦ con m p k ⟧^v γ = ⟦ m ⟧^con (⟦ p ⟧^v γ) (λ a → ⟦ k ⟧^v (γ , a))
  46. ⟦ thunk c ⟧^v γ = ⟦ c ⟧^c γ
  47. ⟦ ⟨⟩ ⟧^v γ = _
  48. ⟦ u , v ⟧^v γ = ⟦ u ⟧^v γ , ⟦ v ⟧^v γ
  49. ⟦ 𝟘-elim v ⟧^v γ = ⊥-elim (⟦ v ⟧^v γ)
  50. ⟦ ι₁ u ⟧^v γ = inj₁ (⟦ u ⟧^v γ)
  51. ⟦ ι₂ v ⟧^v γ = inj₂ (⟦ v ⟧^v γ)
  52. ⟦_⟧^c : ∀ {Γ C c} → Γ ⊢^c c ∶ C → ⟦ Γ ⟧^Ctx → Carrier ⟦ C ⟧^CType
  53. ⟦ return v ⟧^c γ = M.return (⟦ v ⟧^v γ)
  54. where
  55. module M = RawMonad rawMonad
  56. ⟦ _to_ {Σ″ = Σ″}{V = V} c k p q ⟧^c γ = bind ⟦ Σ″ ⋆ V ⟧^CType
  57. (embed (⊆→⇒ p) (⟦ c ⟧^c γ))
  58. (λ u → embed (⊆→⇒ q) (⟦ k ⟧^c (γ , u)))
  59. ⟦ force v ⟧^c γ = ⟦ v ⟧^v γ
  60. ⟦ let′ v be k ⟧^c γ = ⟦ k ⟧^c (γ , ⟦ v ⟧^v γ)
  61. ⟦ ⟨⟩ ⟧^c γ = M.return _
  62. where
  63. module M = RawMonad rawMonad
  64. ⟦ split p k ⟧^c γ = let (u , v) = ⟦ p ⟧^v γ in ⟦ k ⟧^c ((γ , u) , v)
  65. ⟦ π₁ p ⟧^c γ = proj₁ (⟦ p ⟧^c γ)
  66. ⟦ π₂ p ⟧^c γ = proj₂ (⟦ p ⟧^c γ)
  67. ⟦ b , c ⟧^c γ = ⟦ b ⟧^c γ , ⟦ c ⟧^c γ
  68. ⟦ ƛ c ⟧^c γ = λ v → ⟦ c ⟧^c (γ , v)
  69. ⟦ f · v ⟧^c γ = ⟦ f ⟧^c γ (⟦ v ⟧^v γ)
  70. ⟦ op m ⟧^c γ = ⟦ m ⟧^op
  71. ⟦ iter φ v ⟧^c γ = EMA.iter (lemma (⟦ φ ⟧^cs γ)) (⟦ v ⟧^v γ)
  72. where
  73. lemma : ∀ {Δ C} → ⟦ Alg Δ C ⟧^CTypes → ALG ⌊ Δ ⌋^Sig (Carrier ⟦ C ⟧^CType)
  74. lemma {[]} _ (() , _)
  75. lemma {_ ∷ _} (f , γ) (inj₁ p , ih) = f p ih
  76. lemma {_ ∷ _} (_ , γ) (inj₂ s , k) = lemma γ (s , k)
  77. ⟦ run {Σ′ = Σ′} φ c p q ⟧^c γ i = RUN {Σ′ = ⌊ Σ′ ⌋^Sig} (lemma (⟦ φ ⟧^cs γ))
  78. (⇒++→⇒⊎ (⊆→⇒ p)) (⊆→⇒ q) (⟦ c ⟧^c γ) i
  79. where
  80. lemma : ∀ {Σ Σ′ Σ″ I U V} → ⟦ PHomo′ Σ Σ′ U I Σ″ V ⟧^CTypes →
  81. PHOMO′ ⌊ Σ ⌋^Sig ⌊ Σ′ ⌋^Sig ⟦ U ⟧^VType ⟦ I ⟧^VType ⌊ Σ″ ⌋^Sig ⟦ V ⟧^VType
  82. lemma {[]} (f , _) (inj₁ u , _) i = f u i
  83. lemma {[]} (_ , _) (inj₂ () , _) i
  84. lemma {_ ∷ Σ} (f , _) (inj₂ (inj₁ p) , ih) i =
  85. f p (λ a → let w , w′ = ih a in ⊎⋆→++⋆ w , w′) i
  86. lemma {_ ∷ Σ} (_ , g) (inj₁ u , k) i = lemma {Σ} g (inj₁ u , k) i
  87. lemma {_ ∷ Σ} (_ , g) (inj₂ (inj₂ s) , k) i = lemma {Σ} g (inj₂ s , k) i
  88. ⟦_⟧^cs : ∀ {Γ Cs cs} → Γ ⊢^cs cs ∶ Cs → ⟦ Γ ⟧^Ctx → ⟦ Cs ⟧^CTypes
  89. ⟦ [] ⟧^cs γ = _
  90. ⟦ c ∷ cs ⟧^cs γ = ⟦ c ⟧^c γ , ⟦ cs ⟧^cs γ
  91. \end{code}
  92. Remark: assuming the meta-theory is strongly normalising, we get...?