monoids-in-the-category-of-.../src/Category/Kleisli.hs

24 lines
853 B
Haskell

{-# LANGUAGE UndecidableInstances #-}
module Category.Kleisli where
import Data.Functor.Identity (Identity (Identity))
import Functor.Base
import Functor.Compose
import Object.Monoid
import Object.Semigroup
import Relation
import Data.Data (Proxy (Proxy))
import Data.Kind (Type)
data Kleisli m x y = Kleisli { runKleisli :: !(Cod m x (m y)) }
data Cokleisli w x y = Cokleisli { runCokleisli :: !(Cod w (w x) y) }
instance (Monoid Compose m, Cod m ~ (->)) => Reflexive (Kleisli m)
instance (Monoid Compose m, Cod m ~ (->)) => Wide (Kleisli m) where
id = Kleisli (runNat (empty (Proxy @Compose)) id . Identity)
instance (Semigroup (Compose :: (Type -> Type) -> (Type -> Type) -> Type -> Type) m, Functor m, Dom m ~ (->), Cod m ~ (->)) => Transitive (Kleisli m) where
Kleisli g . Kleisli f = Kleisli (runNat append id . Compose . map g . f)