是否有#34; ApplicativeIO"类?

时间:2014-09-26 16:37:36

标签: haskell applicative fam-proposal

Hackage中是否存在类似于MonadIO的类型类,但对于Applicative s,允许根据{{1}轻松将IO操作提升为"applicative composition stacks" }?

如果存在这样的类型类,是否会因Applicative-Monad Proposal的实施而过时?该提案是否涉及放宽对IO的{​​{1}}约束?

1 个答案:

答案 0 :(得分:4)

一年前有a related discussion on haskell-cafe。在Reddit comments我给了an example自然转换(g)从IO到另一个monad,这是一个应用函子态射(即,满足Gabriel Gonzalez提到的法则)但不是monad态射(它不符合与>>=有关的附加法律)。因此,即使在有AMP的世界中,ApplicativeIO mMonadIO m也是完全不同的事情,即使mMonad

在理想的世界中,你有这样的设置:

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

和神奇的仙女会在相应的法律得到满足时准确定义ApplicativeIOMonadIO个实例。