Functor.agda 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. {-# OPTIONS --no-positivity-check #-}
  2. module Functor where
  3. import Sets
  4. open Sets
  5. infixr 40 _+_ _+₂_
  6. infixr 60 _×_ _×₂_
  7. infix 80 _[_]
  8. data U : Set1 where
  9. K : Set -> U
  10. Id : U
  11. _+_ : U -> U -> U
  12. _×_ : U -> U -> U
  13. data U₂ : Set1 where
  14. K₂ : (A : Set) -> U₂
  15. ↖ : U -> U₂
  16. ↗ : U -> U₂
  17. _+₂_ : U₂ -> U₂ -> U₂
  18. _×₂_ : U₂ -> U₂ -> U₂
  19. -- Functor composition
  20. _[_] : U -> U -> U
  21. K A [ H ] = K A
  22. Id [ H ] = H
  23. (F + G) [ H ] = F [ H ] + G [ H ]
  24. (F × G) [ H ] = F [ H ] × G [ H ]
  25. module Semantics where
  26. -- The semantic of a functor
  27. ⟦_⟧ : U -> Set -> Set
  28. ⟦ K A ⟧ X = A
  29. ⟦ Id ⟧ X = X
  30. ⟦ F + G ⟧ X = ⟦ F ⟧ X [+] ⟦ G ⟧ X
  31. ⟦ F × G ⟧ X = ⟦ F ⟧ X [×] ⟦ G ⟧ X
  32. ⟦_⟧₂ : (F : U₂) -> Set -> Set -> Set
  33. ⟦ K₂ A ⟧₂ C J = A
  34. ⟦ ↖ F ⟧₂ C J = ⟦ F ⟧ C
  35. ⟦ ↗ F ⟧₂ C J = ⟦ F ⟧ J
  36. ⟦ F +₂ G ⟧₂ C J = ⟦ F ⟧₂ C J [+] ⟦ G ⟧₂ C J
  37. ⟦ F ×₂ G ⟧₂ C J = ⟦ F ⟧₂ C J [×] ⟦ G ⟧₂ C J
  38. module Recursive where
  39. -- Fixed points (we need to turn off positivity checking since we can't see
  40. -- that ⟦ F ⟧ is covariant).
  41. open Semantics
  42. data μ (F : U) : Set where
  43. inn : ⟦ F ⟧ (μ F) -> μ F
  44. out : {F : U} -> μ F -> ⟦ F ⟧ (μ F)
  45. out (inn f) = f