Why does Control.Monad.Morph.hoist have a Monad limitation?

Control.Monad.Morph includes

 class MFunctor t where hoist :: Monad m => (forall a. ma -> na) -> tmb -> tnb 

As far as I can tell, none of the included instances uses the Monad m restriction. How can I do that? Are there any valid instances that use the restriction (it's a little difficult for me to imagine how, given that hoist id = id )? What is the value of the constraint m , not n ?

+7
functor haskell monads typeclass
source share
1 answer

Control.Monad.Morph is a spinoff from pipes , so I would suggest that it is needed because the MFunctor instance for Proxy needs it ... And, of course, it is used there .

 instance MFunctor (Proxy a' ab' b) where hoist nat p0 = go (observe p0) where go p = case p of Request a' fa -> Request a' (\a -> go (fa a )) Respond b fb' -> Respond b (\b' -> go (fb' b')) M m -> M (nat (m >>= \p' -> return (go p'))) Pure r -> Pure r 

I do not think it was necessary. m >>= return . f m >>= return . f - fmap fm . This should probably be a Functor constraint, and this code precedes the implementation of the proposal proposed by monads.

+6
source share

All Articles