I am trying to define a type class for bi-categories and create it using two categories of categories, functors and natural transformations.
{-
Here is a class class for categories:
class Category (c :: * -> * -> *) where id :: cxx (.) ::cyz -> cxy -> cxz
Here is a class for functors:
class Functor cdf where fmap :: cxy -> d (fx) (fy)
Here is the composition of the functors:
newtype Comp gft = Comp (g (ft))
The composition of two functors must be a functor. However, Haskell does not accept the next instance, because f and g not included in the volume. How would you define fmap here?
instance Functor ce (Comp gf) where fmap :: cxy -> e (Comp gfx) (Comp gfy) fmap = fmap g . fmap f
Here are the natural conversions (the c parameter is not used here, but is useful for the following instance below):
newtype NT fg (c :: * -> * -> *) d = NT {unNT :: forall x. d (fx) (gx) }
Here is the class for bi-categories (Operators .| And .- are respectively vertical and horizontal compositions for 2 cells):
class Bicategory (bicat :: (* -> *) -> (* -> *) -> (* -> * -> *) -> (* -> * -> *) -> *) comp where id1 :: Category d => bicat ffcd (.|) :: Category d => bicat ghcd -> bicat fgcd -> bicat fhcd (.-) :: bicat gg' de -> bicat ff' cd -> bicat (g `comp` f) (g' `comp` f') ce
Categories, functors, and natural transformations should form a bi-category. However, Haskell does not accept the following instance, because in the definition of horizontal composition .- natural transformations of g are not in volume. How can you define horizontal composition (.-) here?
instance Bicategory NT Comp where id1 = NT id n .| m = NT (unNT n . unNT m) (n :: NT gg' de) .- m = NT (unNT n . fmap g (unNT m))