Issue854.lagda 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. % Andreas, Bug filed by Stevan Andjelkovic, June 2013
  2. \subsection{Examples}
  3. \label{examples}
  4. \AgdaHide{
  5. \begin{code}
  6. {-# OPTIONS --sized-types #-}
  7. module Issue854 where
  8. open import Function
  9. open import Data.Unit
  10. open import Data.Product
  11. open import Data.List
  12. open import Data.List.Relation.Unary.Any
  13. open import Data.List.Relation.Binary.Pointwise hiding (refl)
  14. open import Data.Container.FreeMonad using (rawMonad)
  15. open import Relation.Binary.PropositionalEquality
  16. open import Category.Monad
  17. open import Data.List.Relation.Binary.Subset.Propositional
  18. open import Issue854.Types
  19. open import Issue854.Context
  20. open import Issue854.WellTyped
  21. open import Issue854.WellTypedSemantics
  22. \end{code}
  23. }
  24. \begin{code}
  25. ′N : Sig
  26. ′N = (𝟙 , 𝟘) ∷ (𝟙 , 𝟙) ∷ []
  27. N = μ ′N
  28. ze : ∀ {Γ} → Γ ⊢^v _ ∶ N
  29. ze = con (here refl) ⟨⟩ (𝟘-elim (var zero))
  30. pattern su n = con (there (here refl)) ⟨⟩ n
  31. #0 #1 : ∀ {Γ} → Γ ⊢^v _ ∶ N
  32. #0 = ze
  33. #1 = su #0
  34. State : VType → Sig
  35. State S = (𝟙 , S) ∷ (S , 𝟙) ∷ []
  36. -- XXX: get : {m : True (𝟙 , S) ∈? Σ)} → Σ ⋆ S?
  37. state^suc : ∀ {Γ} → Γ ⊢^c _ ∶ State N ⋆ 𝟙
  38. state^suc {Γ} = _to_ (op get · ⟨⟩) (op put · su′) id id
  39. where
  40. get = here refl
  41. put = there (here refl)
  42. su′ : Γ ▻ N ⊢^v _ ∶ N
  43. su′ = con (there (here refl)) ⟨⟩ (var (suc zero))
  44. state^Homo : ∀ {Γ Σ S X} → Γ ⊢^cs _ ∶ PHomo (State S) X S Σ (X ⊗ S)
  45. state^Homo =
  46. ƛ ƛ ƛ (((π₂ (force (var (suc zero)) · var zero)) · var zero)) ∷
  47. ƛ ƛ ƛ ((π₂ (force (var (suc zero)) · ⟨⟩)) · var (suc (suc zero))) ∷
  48. ƛ ƛ return (var (suc zero) , var zero) ∷ []
  49. private
  50. -- XXX: Move to std-lib?
  51. inl-++ : ∀ {A : Set}{xs ys : List A} → xs ⊆ (xs ++ ys)
  52. inl-++ {xs = []} ()
  53. inl-++ {xs = x ∷ xs} (here refl) = here refl
  54. inl-++ {xs = x ∷ xs} (there p) = there (inl-++ p)
  55. inr-++ : ∀ {A : Set}{xs ys : List A} → ys ⊆ (xs ++ ys)
  56. inr-++ {xs = []} p = p
  57. inr-++ {xs = x ∷ xs} p = there (inr-++ {xs = xs} p)
  58. ex-state : [] ⊢^c _ ∶ [] ⋆ (𝟙 ⊗ N)
  59. ex-state = run {Σ′ = State N}{[]} state^Homo state^suc inl-++ id · #0
  60. test-state : ⟦ ex-state ⟧^c tt ≡ ⟦ return (⟨⟩ , #1) ⟧^c tt
  61. test-state = refl
  62. \end{code}