Let bir olmak CCC . Let bir ürün bifunctor olmak . As Kedi CCC, biz köri olabilir :
Fonksiyonel kategori olağan monoidal yapıya sahiptir. Bir monoid bir tek hücreli olan . Sonlu ürünleri üzerinde monoidal yapı olarak kabul ediyoruz .
Bu nedenle monoidal yapıyı korur, bu nedenle bir monoid bir monad ve bir comonoid'i bir comonad'a taşır. Yani, bir rasgele Monoid nakil ağırlık için ( W R I t e r w ) monadın (tanımlamadaki görünüm - W bir monoid olmalıdır). Aynı şekilde bu nakil diyagonal comonoid için Coreader comonad.
Şimdi, somut olarak, Yazarın inşasını açtım.
Başla. Aslında , Haskell'de sadece farklı isimler var. Bir var Haskell Monoid ⟨ w , m bir p s e , n d , m, E m s t y ⟩ :
Writer is a functor, so it must map also morphisms, such as and . I write this as below, though it is invalid in Haskell:
is a natural transformation, a morphism in . By properties of it is a function, which takes and gives a morphism in :
Informally, sums components of type and pumps intact. This is exactly the definition of Writer in Haskell. One obstacle is that for the monad we need
i.e. incompatibility of types. But these functors are isomorphic: by the usual associator for finite products which is a natural isomorphism . Then we define via . I omit a construction of via .
Writer, being a functor, preserves commutative diagrams, i.e. preserves monoid equalities, so we have for granted proved equalities for = a monoid in = a monad in . End.
What about Reader and Cowriter? Reader is adjoint to Coreader, as explained in the definition of Coreader, see link above. Similarly, Cowriter is adjoint to Writer. I did not find a definition of Cowriter, so I made it up by analogy shown in the table:
{- base, Hackage.category-extras -}
import Control.Comonad
import Data.Monoid
data Cowriter w a = Cowriter (w -> a)
instance Functor (Cowriter w) where
fmap f (Cowriter g) = Cowriter (f . g)
instance Monoid w => Copointed (Cowriter w) where
extract (Cowriter g) = g mempty
instance Monoid w => Comonad (Cowriter w) where
duplicate (Cowriter g) = Cowriter
(\w' -> Cowriter (\w -> g (w `mappend` w')))
Below are the simplified definitions of those (co)monads. fr_ob F denotes a mapping of a functor F on objects, fr_mor F denotes a mapping of a functor F on morphisms. There is a monoid object in .
- Writer
- Reader
- Coreader
- Cowriter
The question is that the adjunction in relates functors, not monads. I do not see how the adjunction implies "Coreader is a comonad" "Reader is a monad" and "Writer is a monad" "Cowriter is a comonad".
Remark. I am struggling to provide more context. It requires some work. Especially, if you require categorical purity and those (co)monads were introduced for programmers. Keep nagging! ;)