dfe*_*uer 7 monads haskell functor typeclass
Control.Monad.Morph 包括
class MFunctor t where
hoist :: Monad m => (forall a. m a -> n a) -> t m b -> t n b
Run Code Online (Sandbox Code Playgroud)
据我所知,所包含的实例都没有使用Monad m约束.怎么可能这样做?是否有使用约束的有效实例(考虑到这一点,我有点难以想象hoist id = id)?约束的意义是什么,m而不是n?
Control.Monad.Morph是从管道分离出来的,所以我猜它就在那里,因为MFunctor实例Proxy需要它......当然它已经在那里使用了.
Run Code Online (Sandbox Code Playgroud)instance MFunctor (Proxy a' a b' 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
我不认为这是必要的.m >>= return . f是fmap f m.它可能应该是一个Functor约束,并且该代码早于monad-applicative提案的实现.