polynomial-comonad
Safe HaskellNone
LanguageGHC2021

Data.InternalCategory

Synopsis

Internal categories

class (IQuiver ob mor, Eq ob) => ICategory ob mor | mor -> ob where Source #

ICategory ob mor defines a category "internal to" Type.

There are two ways to define ICategory: with identity and compose or with foldPath.

Definition by identity, compose

This is how internal categories are usually defined: by giving identity morphisms and composition of two morphisms, satisfying the following laws:

Domain and codomain of identity v:

   dom (identity v) == cod (identity v) == v
   

compose is defined exactly on matching morphisms:

   isJust (compose f g) == (cod f == dom g)
   

Domain and codomain of compose f g:

For all f,g,h such that compose f g == Just h,

   dom h == dom f, cod h == cod g
   

Left and Right Unit:

   identity (dom f) compose f == Just f
   
   f compose identity (cod f) == Just f
   

Associativity:

For all f,g,h,

   (compose f g >>= fg -> compose fg h)
     ==
   (compose g h >>= gh -> compose f gh)
   

Given identity and compose operation, foldPath p can be defined as the composition morAll of all morphisms in p (and the identity at source in a case of empty path,) which is guaranteed to be Just morAll and not Nothing.

Definition by foldPath:

This is an alternative definition by giving how to collapse any path on IQuiver ob mor into mor, satisfying the following laws.

folding doesn't change endpoints:

   dom (foldPath p) == dom p
   
   cod (foldPath p) == cod p
   

folding commutes with concatPath:

For any pp :: Path ob (Path ob mor),

   foldPath (concatPath pp) = foldPath (errMapPath id foldPath pp)
   

Note that from folding doesn't change endpoints law, errMapPath id foldPath must be a total function.

folding single edge does nothing:

   foldPath (singlePath f) = f
   

Given foldPath, one can defined identity and compose satisfying the laws above, as

identity :: ob -> mor
identity = foldPath . emptyPath

compose :: mor -> mor -> Maybe mor
compose f g = foldPath $ composePath (singlePath f) (singlePath g)

Minimal complete definition

foldPath | identity, compose

Methods

foldPath :: Path ob mor -> mor Source #

identity :: ob -> mor Source #

compose :: mor -> mor -> Maybe mor Source #

Instances

Instances details
ICategory Void Void Source #

Empty graph

Instance details

Defined in Data.InternalCategory

ICategory () () Source #

A graph with one vertex and one loop on it

Instance details

Defined in Data.InternalCategory

Methods

foldPath :: Path () () -> () Source #

identity :: () -> () Source #

compose :: () -> () -> Maybe () Source #

Eq a => ICategory a (Codisc a) Source # 
Instance details

Defined in Data.InternalCategory.Codiscrete

Methods

foldPath :: Path a (Codisc a) -> Codisc a Source #

identity :: a -> Codisc a Source #

compose :: Codisc a -> Codisc a -> Maybe (Codisc a) Source #

Eq a => ICategory a (Disc a) Source # 
Instance details

Defined in Data.InternalCategory.Discrete

Methods

foldPath :: Path a (Disc a) -> Disc a Source #

identity :: a -> Disc a Source #

compose :: Disc a -> Disc a -> Maybe (Disc a) Source #

Eq ob => ICategory ob (Path ob mor) Source #

Path is the free category

Instance details

Defined in Data.InternalCategory

Methods

foldPath :: Path ob (Path ob mor) -> Path ob mor Source #

identity :: ob -> Path ob mor Source #

compose :: Path ob mor -> Path ob mor -> Maybe (Path ob mor) Source #

(Comonad f, Polynomial f, GEq (Tag f)) => ICategory (Pos f) (Dir f) Source # 
Instance details

Defined in Data.InternalCategory.PolyComonad

Methods

foldPath :: Path (Pos f) (Dir f) -> Dir f Source #

identity :: Pos f -> Dir f Source #

compose :: Dir f -> Dir f -> Maybe (Dir f) Source #

(ICategory v e, ICategory w f) => ICategory (Either v w) (Either e f) Source #

Coproduct of category

Instance details

Defined in Data.InternalCategory

Methods

foldPath :: Path (Either v w) (Either e f) -> Either e f Source #

identity :: Either v w -> Either e f Source #

compose :: Either e f -> Either e f -> Maybe (Either e f) Source #

(ICategory v e, ICategory w f) => ICategory (v, w) (e, f) Source #

Product of category

Instance details

Defined in Data.InternalCategory

Methods

foldPath :: Path (v, w) (e, f) -> (e, f) Source #

identity :: (v, w) -> (e, f) Source #

compose :: (e, f) -> (e, f) -> Maybe (e, f) Source #

Path

data Path v e where Source #

Bundled Patterns

pattern Path :: v -> [e] -> v -> Path v e 
pattern EmptyPath :: v -> Path v e 
pattern NonEmptyPath :: e -> [e] -> Path v e 

Instances

Instances details
Show2 Path Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Path a b -> ShowS #

liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Path a b] -> ShowS #

Eq ob => ICategory ob (Path ob mor) Source #

Path is the free category

Instance details

Defined in Data.InternalCategory

Methods

foldPath :: Path ob (Path ob mor) -> Path ob mor Source #

identity :: ob -> Path ob mor Source #

compose :: Path ob mor -> Path ob mor -> Maybe (Path ob mor) Source #

IQuiver v (Path v e) Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

src :: Path v e -> v Source #

tgt :: Path v e -> v Source #

Show v => Show1 (Path v) Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Path v a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Path v a] -> ShowS #

(Show v, Show e) => Show (Path v e) Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

showsPrec :: Int -> Path v e -> ShowS #

show :: Path v e -> String #

showList :: [Path v e] -> ShowS #

(Eq e, Eq v) => Eq (Path v e) Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

(==) :: Path v e -> Path v e -> Bool #

(/=) :: Path v e -> Path v e -> Bool #

(Ord e, Ord v) => Ord (Path v e) Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

compare :: Path v e -> Path v e -> Ordering #

(<) :: Path v e -> Path v e -> Bool #

(<=) :: Path v e -> Path v e -> Bool #

(>) :: Path v e -> Path v e -> Bool #

(>=) :: Path v e -> Path v e -> Bool #

max :: Path v e -> Path v e -> Path v e #

min :: Path v e -> Path v e -> Path v e #

dom :: ICategory ob mor => mor -> ob Source #

cod :: ICategory ob mor => mor -> ob Source #

(>?>) :: ICategory ob mor => mor -> mor -> Maybe mor infixr 1 Source #

Reexport

class IQuiver v e | e -> v where Source #

Class for Quiver represented by types of edges and vertices

Methods

src :: e -> v Source #

tgt :: e -> v Source #

Instances

Instances details
IQuiver Void Void Source #

Empty graph

Instance details

Defined in Data.InternalQuiver

Methods

src :: Void -> Void Source #

tgt :: Void -> Void Source #

IQuiver () () Source #

A graph with one vertex and one loop on it

Instance details

Defined in Data.InternalQuiver

Methods

src :: () -> () Source #

tgt :: () -> () Source #

IQuiver a (Codisc a) Source # 
Instance details

Defined in Data.InternalCategory.Codiscrete

Methods

src :: Codisc a -> a Source #

tgt :: Codisc a -> a Source #

IQuiver a (Disc a) Source # 
Instance details

Defined in Data.InternalCategory.Discrete

Methods

src :: Disc a -> a Source #

tgt :: Disc a -> a Source #

IQuiver v (Path v e) Source # 
Instance details

Defined in Data.InternalQuiver.Path

Methods

src :: Path v e -> v Source #

tgt :: Path v e -> v Source #

(Comonad f, Polynomial f, GEq (Tag f)) => IQuiver (Pos f) (Dir f) Source # 
Instance details

Defined in Data.InternalCategory.PolyComonad

Methods

src :: Dir f -> Pos f Source #

tgt :: Dir f -> Pos f Source #

(IQuiver v e, IQuiver w f) => IQuiver (Either v w) (Either e f) Source # 
Instance details

Defined in Data.InternalQuiver

Methods

src :: Either e f -> Either v w Source #

tgt :: Either e f -> Either v w Source #

(IQuiver v e, IQuiver w f) => IQuiver (v, w) (e, f) Source # 
Instance details

Defined in Data.InternalQuiver

Methods

src :: (e, f) -> (v, w) Source #

tgt :: (e, f) -> (v, w) Source #