任意カテゴリにおける自由モノイド関数

1079 ワード

それはしばしば「モナドは内因性のカテゴリーの中のモノイドです.」
ほとんど知られていない事実は、アプリケーションの機能は、製品として日の畳み込みと機能のカテゴリのモノイドです.
また、エンドファンクションの構成と異なった日の畳み込みは、どんな強力なモノイドカテゴリーでも定義できます(基本的にはタプルと関数を持っています).
Hence
{-# LANGUAGE ExistentialQuantification, RankNTypes #-}
import Prelude hiding (Functor (..), Applicative (..))
class Functor f where
  fmap :: Hom a b -> f a -> f b
class Functor f => Monoidal f where
  pure :: Id a -> f a
  join :: Day f f a -> f a
data Day f g a = forall x y. Day (f x) (g y) (Hom (PRODUCT x y) a)
instance Functor (Day f g) where
   fmap f (Day h x y) = Day (f :.: h) x y
data Id a = Id (forall x. Hom x a)
instance Functor Id where
    fmap f (Id x) = Id (f :.: x)
data Free f a = Pure (Id a) | Ap (Day f (Free f) a)
instance Functor (Free f) where
   fmap f (Pure x) = Pure (fmap f x)
   fmap f (Ap x) = Ap (fmap f x)
instance Monoidal (Free f) where
   pure = Pure
   join (Day h (Pure x) y) = Ap h x y
PRODUCTHomが定義されている場合.
ためには、あなたのカテゴリを持っていない可能性のある機能を必要とするフルアプリケーションの機能を持っている.