As State monad can be factorized into Product (Left - Functor) and Reader (Right - Representable).
- Is there a way to factorize Continuation Monad? Below code is my attempt, which wont type check
-- To form a -> (a -> k) -> k
{-# LANGUAGE MultiParamTypeClasses, TypeOperators, InstanceSigs, TypeSynonymInstances #-}
type (<-:) o i = i -> o
-- I Dont think we can have Functor & Representable for this type synonym
class Isomorphism a b where
from :: a -> b
to :: b -> a
instance Adjunction ((<-:) e) ((<-:) e) where
unit :: a -> (a -> e) -> e
unit a handler = handler a
counit :: (a -> e) -> e -> a
counit f e = undefined -- If we have a constraint on Isomorphism a e then we can implement this
Is there a list of Left & Rights Adjoints that form monads?
I have read that, given a pair of adjoints, they form a unique Monad & Comonad but, given a Monad, it can be Factorized into multiple Factors. Is there any example of this?
This doesn't typecheck because the class
Adjunctiononly represents a small subset of adjunctions, where both functors are endofunctors on Hask.As it turns out, this is not the case for the adjunction
(<-:) r -| (<-:) r. There are two subtly different functors here:f = (<-:) r, the functor from Hask to Op(Hask) (the opposite category of Hask, sometimes also denoted Hask^op)g = (<-:) r, the functor from Op(Hask) to HaskIn particular, the
counitshould be a natural transformation in the Op(Hask) category, which flips arrows around:In fact,
counitcoincides withunitin this adjunction.To capture this properly, we need to generalize the
FunctorandAdjunctionclasses so we can model adjunctions between different categories:Then we get again that
Composeis a monad (and a comonad if we flip the adjunction):and
Contis merely a special case of that:See also this gist for more details: https://gist.github.com/Lysxia/beb6f9df9777bbf56fe5b42de04e6c64
The factorization is generally not unique. Once you've generalized adjunctions as above, then you can at least factor any monad
Mas an adjunction between its Kleisli category and its base category (in this case, Hask).I don't know whether the continuation monad corresponds to an adjunction between endofunctors on Hask.
See also the nCatLab article on monads: https://ncatlab.org/nlab/show/monad#RelationToAdjunctionsAndMonadicity