我在最近的一篇博文中写了关于transformers的文章,有人问:“人们使用Control.Applicative.Lift做什么?”我无法回答这个问题,所以我向StackOverflow重复这个问题-- Control.Applicative.Lift是用来做什么的?
我在包中看到了一个使用它的例子,但我似乎不能完全解析它所做的事情。在野外还有谁知道其他的例子吗?
发布于 2012-12-24 15:02:07
电梯是一个相对较新的贡献:
data Lift f a = Pure a | Other (f a)也就是说,给定一个函子f,您可以通过使用纯值组合f来获得一个新的函子。
包本身给出了一个例子:
-- | An applicative functor that collects a monoid (e.g. lists) of errors.
-- A sequence of computations fails if any of its components do, but
-- unlike monads made with 'ErrorT' from "Control.Monad.Trans.Error",
-- these computations continue after an error, collecting all the errors.
type Errors e = Lift (Constant e)
-- | Report an error.
failure :: Monoid e => e -> Errors e a
failure e = Other (Constant e)不过,我不知道这有什么疯狂的用途。
https://stackoverflow.com/questions/14022791
复制相似问题