函数式java:P1是什么东西?
我正在查看 Function Java,但不明白 是什么P1 是。有人可以解释和/或举个例子吗?
(背景:我确实知道柯里化和闭包是什么)
I'm looking at Functional Java and I don't understand what a P1 is. Could anyone explain and/or give an example?
(background: I do know what currying and closures are)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这直接取自 Functional Java 的 Google Code 项目:
This is taken straight from the Google Code project for Functional Java:
P1
看起来像 1 元素、琐碎的产品类型 。在 Haskell 中,它会写成:(Haskell 中的
Identity
类型)。也就是说,它是一个容纳其他类型
a
的容器。这种类型还实现了最简单的 monad,
Identity
,它允许将函数不透明地应用于框的内容。从计算角度来看,没有理由使用 Identity monad,而不是简单地将函数应用于其参数的简单行为,但是,它在 monad 转换器堆栈的设计中可能很有用。
身份 monad 的 monad 实现很简单,
如您所见,这只是函数应用。
P1
looks like the 1-element, trivial product type. In Haskell it would be written as:(the
Identity
type in Haskell).that is, it is a container that holds some other type
a
.This type also implements the simplest monad,
Identity
, which allows for functions to be opaquely applied to the contents of the box.Computationally, there is no reason to use the
Identity
monad instead of the much simpler act of simply applying functions to their arguments, however, it can be useful in the design of monad transformer stacks.The monad implementation of the identity monad is trivial,
As you can see, this is just function application.
啊哈哈,找到了这篇文章:
因此,我可以使用返回
P1
的内容,而不是直接返回类型 T,就像 Google CollectionsSupplier
,并仅在P1 时计算包含的值._1()
被调用。(呵呵,这篇博文 Java 中的延迟错误处理也很有趣……)
aha, found this post:
So instead of returning type T directly, I can have something that returns
P1<T>
, much like Google CollectionsSupplier<T>
, and have it compute the contained value only whenP1._1()
is called.(huh, this blog post Lazy Error Handling in Java was interesting too.....)