You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found this construction, and I thought I should make an issue here for reference (and possible future inclusion).
Through some isomorphism arithmetic, it's possible to find a direct-style Co:
forall r. w (a -> r) -> r
~ forall r x. (x -> a -> r) -> w x -> r
~ forall r x. ((x, a) -> r) -> w x -> r
~ forall x. w x -> (x, a)
which is easily generalizable to a monad transformer:
newtypeCovTwma=CovT{runCovT::forallx.wx->m (x, a) }instanceFunctorm=>Functor (CovTwm) wherefmap f cov =CovT$\w -> (fmap.fmap) f (runCovT cov w)
instance (Comonadw, Monadm) =>Applicative (CovTwm) wherepure a =CovT$\w ->pure (extract w, a)
(<*>)= ap
instance (Comonadw, Monadm) =>Monad (CovTwm) where
m >>= f =CovT$\w ->do
(w', a) <- runCovT m (duplicate w)
runCovT (f a) w'
The obvious difference here is that CovT w m is covariant in m. Also, unlike CoT, CovT (Store s) m is directly isomorphic to StateT s m (rather than the CPS version of StateT). In the same way, CovT ((,) r) m ~ ReaderT r m, CovT ((->) s) m ~ WriterT s m, etc.
The text was updated successfully, but these errors were encountered:
Found this construction, and I thought I should make an issue here for reference (and possible future inclusion).
Through some isomorphism arithmetic, it's possible to find a direct-style
Co
:which is easily generalizable to a monad transformer:
The obvious difference here is that
CovT w m
is covariant inm
. Also, unlikeCoT
,CovT (Store s) m
is directly isomorphic toStateT s m
(rather than the CPS version ofStateT
). In the same way,CovT ((,) r) m ~ ReaderT r m
,CovT ((->) s) m ~ WriterT s m
, etc.The text was updated successfully, but these errors were encountered: