首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Control.Applicative.Lift有什么用?

Control.Applicative.Lift有什么用?
EN

Stack Overflow用户
提问于 2012-12-24 14:53:39
回答 1查看 1.1K关注 0票数 21

我在最近的一篇博文中写了关于transformers的文章,有人问:“人们使用Control.Applicative.Lift做什么?”我无法回答这个问题,所以我向StackOverflow重复这个问题-- Control.Applicative.Lift是用来做什么的?

我在包中看到了一个使用它的例子,但我似乎不能完全解析它所做的事情。在野外还有谁知道其他的例子吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-24 15:02:07

电梯是一个相对较新的贡献:

代码语言:javascript
复制
data Lift f a = Pure a | Other (f a)

也就是说,给定一个函子f,您可以通过使用纯值组合f来获得一个新的函子。

包本身给出了一个例子:

代码语言:javascript
复制
-- | 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)

不过,我不知道这有什么疯狂的用途。

票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14022791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档