35 lines
1014 B
Haskell
35 lines
1014 B
Haskell
module Object.Monoid where
|
|
|
|
import Functor.Base
|
|
import Functor.Bifunctor
|
|
import Functor.Compose
|
|
import Functor.Identity
|
|
import Object.Semigroup
|
|
|
|
import Data.Data (Proxy (Proxy))
|
|
import Data.Kind (Constraint, Type)
|
|
|
|
type Monoid :: (k -> k -> k) -> k -> Constraint
|
|
class Semigroup prod m => Monoid prod m where
|
|
empty :: proxy prod -> Dom1 prod (Unit prod) m
|
|
|
|
type Comonoid :: (k -> k -> k) -> k -> Constraint
|
|
class Cosemigroup coprod w => Comonoid coprod w where
|
|
destroy :: proxy coprod -> Dom1 coprod w (Unit coprod)
|
|
|
|
empty' :: (Monoid (,) m) => m
|
|
empty' = empty (Proxy :: Proxy (,)) ()
|
|
|
|
instance Comonoid (,) a where
|
|
destroy _ = \_ -> ()
|
|
|
|
-- | A monad is a monoid in the category of endofunctors.
|
|
type Monad :: (Type -> Type) -> Constraint
|
|
type Monad m = (Endofunctor m, Monoid Compose m)
|
|
|
|
-- | A comonad is a comonoid in the category of endofunctors.
|
|
type Comonad :: (Type -> Type) -> Constraint
|
|
type Comonad m = (Endofunctor m, Comonoid Compose m)
|
|
|
|
-- TODO: Re-implement bind and cobind in rewrite.
|