module Control.Category.Cartesian
(
Semicartesian (..),
(/\),
Semicocartesian (..),
(\/),
Cartesian (..),
Cocartesian (..),
)
where
import Control.Category (id, (>>>))
import Control.Category.Tensor (Iso (..), Symmetric, Tensor (..), (#))
import Data.Functor.Contravariant (Op (..))
import Data.Void (Void, absurd)
import Prelude hiding (fst, id, snd)
class Symmetric cat t => Semicartesian cat t where
split :: cat a (a `t` a)
fork :: cat a x -> cat a y -> cat a (x `t` y)
fork cat a x
f cat a y
g = forall (cat :: * -> * -> *) (t :: * -> * -> *) a.
Semicartesian cat t =>
cat a (t a a)
split forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> cat a x
f forall (cat1 :: * -> * -> *) (cat2 :: * -> * -> *)
(cat3 :: * -> * -> *) (t :: * -> * -> *) a b c d.
GBifunctor cat1 cat2 cat3 t =>
cat1 a b -> cat2 c d -> cat3 (t a c) (t b d)
# cat a y
g
{-# MINIMAL split #-}
infixr 9 /\
(/\) :: Semicartesian cat t => cat a x -> cat a y -> cat a (x `t` y)
/\ :: forall (cat :: * -> * -> *) (t :: * -> * -> *) a x y.
Semicartesian cat t =>
cat a x -> cat a y -> cat a (t x y)
(/\) = forall (cat :: * -> * -> *) (t :: * -> * -> *) a x y.
Semicartesian cat t =>
cat a x -> cat a y -> cat a (t x y)
fork
instance Semicartesian (->) (,) where
split :: a -> (a, a)
split :: forall a. a -> (a, a)
split a
a = (a
a, a
a)
instance Semicocartesian (->) t => Semicartesian Op t where
split :: Semicocartesian (->) t => Op a (t a a)
split :: forall a. Semicocartesian (->) t => Op a (t a a)
split = forall a b. (b -> a) -> Op a b
Op forall (cat :: * -> * -> *) (t :: * -> * -> *) a.
Semicocartesian cat t =>
cat (t a a) a
merge
class Symmetric cat t => Semicocartesian cat t where
merge :: cat (a `t` a) a
fuse :: cat x a -> cat y a -> cat (x `t` y) a
fuse cat x a
f cat y a
g = cat x a
f forall (cat1 :: * -> * -> *) (cat2 :: * -> * -> *)
(cat3 :: * -> * -> *) (t :: * -> * -> *) a b c d.
GBifunctor cat1 cat2 cat3 t =>
cat1 a b -> cat2 c d -> cat3 (t a c) (t b d)
# cat y a
g forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (cat :: * -> * -> *) (t :: * -> * -> *) a.
Semicocartesian cat t =>
cat (t a a) a
merge
{-# MINIMAL merge #-}
infixr 9 \/
(\/) :: Semicocartesian cat t => cat x a -> cat y a -> cat (x `t` y) a
\/ :: forall (cat :: * -> * -> *) (t :: * -> * -> *) x a y.
Semicocartesian cat t =>
cat x a -> cat y a -> cat (t x y) a
(\/) = forall (cat :: * -> * -> *) (t :: * -> * -> *) x a y.
Semicocartesian cat t =>
cat x a -> cat y a -> cat (t x y) a
fuse
instance Semicocartesian (->) Either where
merge :: Either a a -> a
merge :: forall a. Either a a -> a
merge = forall x a y. (x -> a) -> (y -> a) -> Either x y -> a
either forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
instance Semicartesian (->) t => Semicocartesian Op t where
merge :: Semicartesian (->) t => Op (t a a) a
merge :: forall a. Semicartesian (->) t => Op (t a a) a
merge = forall a b. (b -> a) -> Op a b
Op forall (cat :: * -> * -> *) (t :: * -> * -> *) a.
Semicartesian cat t =>
cat a (t a a)
split
class (Semicartesian cat t, Tensor cat t i) => Cartesian cat t i | i -> t, t -> i where
kill :: cat a i
projl :: cat (x `t` y) x
projl = forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id forall (cat1 :: * -> * -> *) (cat2 :: * -> * -> *)
(cat3 :: * -> * -> *) (t :: * -> * -> *) a b c d.
GBifunctor cat1 cat2 cat3 t =>
cat1 a b -> cat2 c d -> cat3 (t a c) (t b d)
# forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Cartesian cat t i =>
cat a i
kill forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (cat :: * -> * -> *) a b. Iso cat a b -> cat a b
fwd forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Tensor cat t i =>
Iso cat (t a i) a
unitr
projr :: cat (x `t` y) y
projr = forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Cartesian cat t i =>
cat a i
kill forall (cat1 :: * -> * -> *) (cat2 :: * -> * -> *)
(cat3 :: * -> * -> *) (t :: * -> * -> *) a b c d.
GBifunctor cat1 cat2 cat3 t =>
cat1 a b -> cat2 c d -> cat3 (t a c) (t b d)
# forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (cat :: * -> * -> *) a b. Iso cat a b -> cat a b
fwd forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Tensor cat t i =>
Iso cat (t i a) a
unitl
unfork :: cat a (x `t` y) -> (cat a x, cat a y)
unfork cat a (t x y)
h = (cat a (t x y)
h forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (cat :: * -> * -> *) (t :: * -> * -> *) i x y.
Cartesian cat t i =>
cat (t x y) x
projl, cat a (t x y)
h forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (cat :: * -> * -> *) (t :: * -> * -> *) i x y.
Cartesian cat t i =>
cat (t x y) y
projr)
{-# MINIMAL kill #-}
instance Cartesian (->) (,) () where
kill :: a -> ()
kill :: forall a. a -> ()
kill = forall a b. a -> b -> a
const ()
instance Cocartesian (->) t i => Cartesian Op t i where
kill :: Cocartesian (->) t i => Op a i
kill :: forall a. Cocartesian (->) t i => Op a i
kill = forall a b. (b -> a) -> Op a b
Op forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Cocartesian cat t i =>
cat i a
spawn
class (Semicocartesian cat t, Tensor cat t i) => Cocartesian cat t i | i -> t, t -> i where
spawn :: cat i a
incll :: cat x (x `t` y)
incll = forall (cat :: * -> * -> *) a b. Iso cat a b -> cat b a
bwd forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Tensor cat t i =>
Iso cat (t a i) a
unitr forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id forall (cat1 :: * -> * -> *) (cat2 :: * -> * -> *)
(cat3 :: * -> * -> *) (t :: * -> * -> *) a b c d.
GBifunctor cat1 cat2 cat3 t =>
cat1 a b -> cat2 c d -> cat3 (t a c) (t b d)
# forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Cocartesian cat t i =>
cat i a
spawn
inclr :: cat y (x `t` y)
inclr = forall (cat :: * -> * -> *) a b. Iso cat a b -> cat b a
bwd forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Tensor cat t i =>
Iso cat (t i a) a
unitl forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Cocartesian cat t i =>
cat i a
spawn forall (cat1 :: * -> * -> *) (cat2 :: * -> * -> *)
(cat3 :: * -> * -> *) (t :: * -> * -> *) a b c d.
GBifunctor cat1 cat2 cat3 t =>
cat1 a b -> cat2 c d -> cat3 (t a c) (t b d)
# forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
unfuse :: cat (x `t` y) a -> (cat x a, cat y a)
unfuse cat (t x y) a
h = (forall (cat :: * -> * -> *) (t :: * -> * -> *) i x y.
Cocartesian cat t i =>
cat x (t x y)
incll forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> cat (t x y) a
h, forall (cat :: * -> * -> *) (t :: * -> * -> *) i y x.
Cocartesian cat t i =>
cat y (t x y)
inclr forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> cat (t x y) a
h)
{-# MINIMAL spawn #-}
instance Cartesian (->) t i => Cocartesian Op t i where
spawn :: Cartesian (->) t i => Op i a
spawn :: forall a. Cartesian (->) t i => Op i a
spawn = forall a b. (b -> a) -> Op a b
Op forall (cat :: * -> * -> *) (t :: * -> * -> *) i a.
Cartesian cat t i =>
cat a i
kill
instance Cocartesian (->) Either Void where
spawn :: Void -> a
spawn :: forall a. Void -> a
spawn = forall a. Void -> a
absurd