0 | module Control.Category.Cocartesian
2 | import Control.Category.Core
3 | import Control.Category.Functor
4 | import Control.Category.Monoidal
5 | import Control.Category.Braided
6 | import Control.Category.Cartesian
11 | import Data.Morphisms
39 | interface Monoidal cat ten i =>
40 | Cocartesian (0 cat : Hom obj) (ten : obj -> obj -> obj) (i : obj) | cat,ten where
41 | constructor MkCocartesian
47 | injl : {a,b : _} -> cat a (a `ten` b)
48 | injl = Core.(.) {cat} (mapr' {cat,f=ten} $
intro {ten}) (unitr' {cat,ten,i})
51 | injr : {a,b : _} -> cat b (a `ten` b)
52 | injr = Core.(.) {cat} (mapl' {cat,f=ten} $
intro {ten}) (unitl' {cat,ten,i})
55 | coprod : {a,a',b : _} -> cat a b -> cat a' b -> cat (a `ten` a') b
56 | coprod f g = Core.(.) merge (bimap' {f=ten} f g)
59 | merge : {a : _} -> cat (a `ten` a) a
60 | merge = Cocartesian.coprod {ten} Core.id Core.id
63 | intro : {a : _} -> cat i a
64 | intro = Core.(.) (unitl {ten}) injl
70 | public export %inline %tcinline
71 | (\|/) : {ten,i : _} -> Cocartesian cat ten i => {a,a',b : _} ->
72 | cat a b -> cat a' b -> cat (a `ten` a') b
77 | PreCocartesian : (cat : Hom obj) -> (ten : obj -> obj -> obj) -> (i : obj) -> Type
78 | PreCocartesian = Cocartesian
87 | inj : Cocartesian cat ten i => {xs : _} -> (x : Fin (length xs)) -> cat (index' xs x) (TenSeq ten i xs)
88 | inj @{c@(MkCocartesian{})} {xs=[_]} FZ = id
89 | inj @{c@(MkCocartesian{})} {xs=[_,_]} (FS FZ) = injr
90 | inj @{c@(MkCocartesian{})} {xs=_::_::_} FZ = injl
91 | inj @{c@(MkCocartesian{})} {xs=_::_::_} (FS x) = injr . inj x
98 | coswizzle : Cocartesian cat ten i => {xs : _} ->
99 | (sw : Swizzle (length xs)) -> cat (TenSeq ten i $
swizzleList xs sw) (TenSeq ten i xs)
100 | coswizzle @{c@(MkCocartesian{})} [] = intro {ten}
101 | coswizzle @{c@(MkCocartesian{})} {xs=_::_} [i] = inj i
102 | coswizzle @{c@(MkCocartesian{})} {xs=_::_} (i::is@(_::_)) = coprod (inj {ten} i) (coswizzle is)
113 | [FromCocartesian] {ten,i : _} -> Cocartesian cat ten i => Braided cat ten i where
114 | braid = coprod injr injl
116 | namespace MonSymmetric
120 | [FromCocartesian] {ten,i : _} -> Cocartesian cat ten i => MonSymmetric cat ten i
121 | using Braided.FromCocartesian where
123 | let tb = toList $
permSeq p
124 | in replace {p = flip cat _ . TenSeq ten i} (believe_me $
Refl {x=()}) $
125 | coswizzle {xs = permuteList xs p} $
rewrite permuteListLength xs p in tb
133 | Cocartesian Morphism Either Void where
136 | coprod (Mor f) (Mor g) = Mor $
either f g
137 | merge = Mor fromEither
140 | namespace Cocartesian
142 | [Function] Cocartesian (~~>) Either Void
143 | using Braided.FuncEither where
146 | coprod f g = either f g
151 | Monad m => Cocartesian (Kleislimorphism m) Either Void where
152 | injl = Kleisli $
pure . Left
153 | injr = Kleisli $
pure . Right
154 | coprod (Kleisli f) (Kleisli g) = Kleisli $
either f g
155 | merge = Kleisli $
pure . fromEither
156 | intro = Kleisli $
pure . absurd