Functor.agda 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. module Functor where
  2. import Logic.Identity as Id
  3. import Category
  4. import Logic.ChainReasoning
  5. open Category
  6. open Poly-Cat
  7. private
  8. module Fun where
  9. data Functor (ℂ ⅅ : Cat) : Set1 where
  10. functor : (F : Obj ℂ -> Obj ⅅ)
  11. (map : {A B : Obj ℂ} -> A ─→ B -> F A ─→ F B)
  12. (mapId : {A : Obj ℂ} -> map (id {A = A}) == id)
  13. (mapCompose : {A B C : Obj ℂ}{f : B ─→ C}{g : A ─→ B} ->
  14. map (f ∘ g) == map f ∘ map g
  15. ) -> Functor ℂ ⅅ
  16. open Fun public
  17. module Projections where
  18. Map : {ℂ ⅅ : Cat} -> Functor ℂ ⅅ -> Obj ℂ -> Obj ⅅ
  19. Map (functor F _ _ _) = F
  20. map : {ℂ ⅅ : Cat}(F : Functor ℂ ⅅ)
  21. {A B : Obj ℂ} -> A ─→ B -> Map F A ─→ Map F B
  22. map (functor _ m _ _) = m
  23. mapId : {ℂ ⅅ : Cat}(F : Functor ℂ ⅅ)
  24. {A : Obj ℂ} -> map F id == id {A = Map F A}
  25. mapId (functor _ _ i _) = i
  26. mapCompose : {ℂ ⅅ : Cat}(F : Functor ℂ ⅅ)
  27. {A B C : Obj ℂ}{f : B ─→ C}{g : A ─→ B} ->
  28. map F (f ∘ g) == map F f ∘ map F g
  29. mapCompose (functor _ _ _ c) = c
  30. module Functor {ℂ ⅅ : Cat}(F : Functor ℂ ⅅ) where
  31. module P = Projections
  32. Map : Obj ℂ -> Obj ⅅ
  33. Map = P.Map F
  34. map : {A B : Obj ℂ} -> A ─→ B -> Map A ─→ Map B
  35. map = P.map F
  36. mapId : {A : Obj ℂ} -> map id == id {A = Map A}
  37. mapId = P.mapId F
  38. mapCompose : {A B C : Obj ℂ}{f : B ─→ C}{g : A ─→ B} ->
  39. map (f ∘ g) == map f ∘ map g
  40. mapCompose = P.mapCompose F
  41. module Functors where
  42. Id : {ℂ : Cat} -> Functor ℂ ℂ
  43. Id = functor (\A -> A) (\f -> f) (\{A} -> refl) (\{A}{B}{C}{f}{g} -> refl)
  44. _○_ : {ℂ ℚ ℝ : Cat} -> Functor ℚ ℝ -> Functor ℂ ℚ -> Functor ℂ ℝ
  45. _○_ {ℂ}{ℚ}{ℝ} F G = functor FG m mid mcomp
  46. where
  47. module F = Functor F
  48. module G = Functor G
  49. FG : Obj ℂ -> Obj ℝ
  50. FG A = F.Map (G.Map A)
  51. m : {A B : Obj ℂ} -> A ─→ B -> FG A ─→ FG B
  52. m f = F.map (G.map f)
  53. mid : {A : Obj ℂ} -> m (id {A = A}) == id
  54. mid = chain> F.map (G.map id)
  55. === F.map id by ? -- cong F.map G.mapId
  56. === id by F.mapId
  57. where
  58. open module Chain = Logic.ChainReasoning.Mono.Homogenous _==_
  59. (\f -> refl)
  60. (\f g h -> trans)
  61. mcomp : {A B C : Obj ℂ}{f : B ─→ C}{g : A ─→ B} ->
  62. m (f ∘ g) == m f ∘ m g
  63. mcomp {f = f}{g = g} =
  64. chain> F.map (G.map (f ∘ g))
  65. === F.map (G.map f ∘ G.map g)
  66. by ? -- cong F.map G.mapCompose
  67. === F.map (G.map f) ∘ F.map (G.map g)
  68. by F.mapCompose
  69. where
  70. open module Chain = Logic.ChainReasoning.Mono.Homogenous _==_
  71. (\f -> refl)
  72. (\f g h -> trans)