임의의 범주 중의 자유 반함

1039 단어
사람들은 늘 농담으로 "쪽지는 내신 범주 중의 반군"이라고 말한다.
편지의 응용은 편지의 범주 중의 반군이고 그 곱셈은 일권적이다.
내신자 합성과 달리 일권적은 어떤 강호반류에도 정의할 수 있다(기본적으로 원조와 함수만 있다)
그러므로
{-# 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는 사용자가 정의합니다.
온전한 응용 프로그램 편지를 가지기 위해서는 클래스에 없는 함수가 필요합니다.

좋은 웹페이지 즐겨찾기