[英]Is there an “ApplicativeIO” class?
Is there somewhere in Hackage a typeclass analogous to MonadIO
but for Applicative
s, that allows one to easily lift IO
actions to "applicative composition stacks" based on IO
? 有没有什么地方在Hackage一个类型类类似于
MonadIO
但对于Applicative
S,使人们得以轻松举起IO
行动,以“应用性成分栈”基于IO
?
If such a typeclass existed, would it be made obsolete by the implementation of the Applicative-Monad Proposal ? 如果存在这样的类型类,是否会因实施“ 申请Monad提案”而过时? Does the proposal involve a relaxation on the
Monad
constraint for MonadIO
? 该提案是否涉及
MonadIO
对Monad
约束的MonadIO
?
There was a related discussion on haskell-cafe a year ago. 一年前有一个关于haskell-cafe的相关讨论 。 In the Reddit comments I gave an example of a natural transformation (
g
) from IO to another monad that is an applicative functor morphism (ie, satisfies the laws that Gabriel Gonzalez mentioned) but is not a monad morphism (it does not satisfy the additional law relating to >>=
). 在Reddit评论中,我给出了一个自然转换的例子 (
g
)从IO到另一个monad,这是一个应用函子态射(即,满足Gabriel Gonzalez提到的定律)但不是monad态射(它不满足额外的态度)有关>>=
)的法律。 So, even in a world with AMP, ApplicativeIO m
and MonadIO m
are really different things, even when m
is a Monad
! 因此,即使在具有AMP的世界中,
ApplicativeIO m
和MonadIO m
也是不同的东西,即使m
是Monad
!
In an ideal world you'd have a setup like this: 在理想的世界中,你有这样的设置:
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
and magical fairies would define ApplicativeIO
and MonadIO
instances exactly when the corresponding laws were satisfied. 当相应的法律得到满足时,神奇的仙女会准确定义
ApplicativeIO
和MonadIO
实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.