Hackage中是否存在类似于MonadIO
的类型类,但对于Applicative
s,允许根据{{1}轻松将IO
操作提升为"applicative composition stacks" }?
如果存在这样的类型类,是否会因Applicative-Monad Proposal的实施而过时?该提案是否涉及放宽对IO
的{{1}}约束?
答案 0 :(得分:4)
一年前有a related discussion on haskell-cafe。在Reddit comments我给了an example自然转换(g
)从IO到另一个monad,这是一个应用函子态射(即,满足Gabriel Gonzalez提到的法则)但不是monad态射(它不符合与>>=
有关的附加法律)。因此,即使在有AMP的世界中,ApplicativeIO m
和MonadIO m
也是完全不同的事情,即使m
是Monad
!
在理想的世界中,你有这样的设置:
class Functor f => FunctorIO f where
liftIO :: IO a -> f a
-- such that liftIO is a natural transformation (automatic, by parametricity)
class (Applicative f, FunctorIO f) => ApplicativeIO f where
-- ... and liftIO is an applicative functor morphism
class (Monad f, ApplicativeIO f) => MonadIO f where
-- ... and liftIO is a monad morphism
和神奇的仙女会在相应的法律得到满足时准确定义ApplicativeIO
和MonadIO
个实例。