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
9 | import Data.Morphisms
37 | interface Monoidal cat ten i =>
38 | Cocartesian (0 cat : Hom obj) (ten : obj -> obj -> obj) (i : obj) | cat,ten where
39 | constructor MkCocartesian
45 | injl : {a,b : _} -> cat a (a `ten` b)
46 | injl = Core.(.) {cat} (mapr' {cat,f=ten} $
intro {ten}) (unitr' {cat,ten,i})
49 | injr : {a,b : _} -> cat b (a `ten` b)
50 | injr = Core.(.) {cat} (mapl' {cat,f=ten} $
intro {ten}) (unitl' {cat,ten,i})
53 | coprod : {a,a',b : _} -> cat a b -> cat a' b -> cat (a `ten` a') b
54 | coprod f g = Core.(.) merge (bimap' {f=ten} f g)
57 | merge : {a : _} -> cat (a `ten` a) a
58 | merge = Cocartesian.coprod {ten} Core.id Core.id
61 | intro : {a : _} -> cat i a
62 | intro = Core.(.) (unitl {ten}) injl
68 | public export %inline %tcinline
69 | (\|/) : {ten,i : _} -> Cocartesian cat ten i => {a,a',b : _} ->
70 | cat a b -> cat a' b -> cat (a `ten` a') b
75 | PreCocartesian : (cat : Hom obj) -> (ten : obj -> obj -> obj) -> (i : obj) -> Type
76 | PreCocartesian = Cocartesian
84 | inj : Cocartesian cat ten i => {xs : _} -> (x : Fin (length xs)) -> cat (index' xs x) (TenSeq ten i xs)
85 | inj @{c@(MkCocartesian{})} {xs=[_]} FZ = id
86 | inj @{c@(MkCocartesian{})} {xs=[_,_]} (FS FZ) = injr
87 | inj @{c@(MkCocartesian{})} {xs=_::_::_} FZ = injl
88 | inj @{c@(MkCocartesian{})} {xs=_::_::_} (FS x) = injr . inj x
99 | [FromCocartesian] {ten,i : _} -> Cocartesian cat ten i => Braided cat ten i where
100 | braid = coprod injr injl
108 | Cocartesian Morphism Either Void where
111 | coprod (Mor f) (Mor g) = Mor $
either f g
112 | merge = Mor fromEither
115 | namespace Cocartesian
117 | [Function] Cocartesian (~~>) Either Void
118 | using Braided.FuncEither where
121 | coprod f g = either f g
126 | Monad m => Cocartesian (Kleislimorphism m) Either Void where
127 | injl = Kleisli $
pure . Left
128 | injr = Kleisli $
pure . Right
129 | coprod (Kleisli f) (Kleisli g) = Kleisli $
either f g
130 | merge = Kleisli $
pure . fromEither
131 | intro = Kleisli $
pure . absurd