I have an accompanying transformer
data Step yma = Done a | Yield y (CoT yma) data CoT yma = CoT (m (Step yma))
with Monad instance
unCoT :: CoT yma -> m (Step yma) unCoT (CoT m) = m instance Monad m => Monad (CoT ym) where return = CoT . return . Done CoT x >>= f = CoT $ do x' <- x case x' of Done a -> unCoT (fa) Yield yx' -> return (Yield y (x' >>= f))
If I define an MFunctor class with the constraints of Monad m and Monad n , I can define hoist
class MFunctor t where hoist :: (Monad n, Monad m) => (forall a. ma -> na) -> tmb -> tnb instance MFunctor (CoT y) where hoist f (CoT m) = CoT $ do step <- fm return (case step of Done x -> Done x Yield ym' -> Yield y (hoist f m'))
But mmorph hoist has a limitation of Monad m . Can I define my hoist without it, or is it the lack of commonality of MFunctor ?
EDITOR: I designed it, maybe! But my question still remains: are we sure that there is no commonality here?
instance MFunctor (CoT y) where hoist f (CoT m) = CoT $ f $ do step <- m return (case step of Done x -> Done x Yield ym' -> Yield y (hoist f m'))
haskell
Tom ellis
source share