Y-Combinator实例 [英] Y-Combinator Practical Example

查看:125
本文介绍了Y-Combinator实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在阅读关于函数式编程的一些知识,并且我正在努力研究Y-Combinator。我知道您可以使用Y-Combinator以不直接支持递归的语言有效地实现递归。然而,我可能使用的每种语言已经支持递归,所以我不确定使用Y-Combinator是多么有用。



是我错过了Y-Combinator使用的更好的实例吗?有没有人真的在实际生产代码中使用过?或者是使用Y-Combinator实际上只是一种令人挠头的学术练习(尽管它非常酷)。

m会不同意其他答案:定点(Y)组合器确实具有实际应用,但需要一个非常富有想象力的头脑才能找到它们。像布鲁斯麦克亚当。这是他的论文摘要那关于包裹它向上


用于计算固定点的Y组合器可以用标准ML表示。它经常用作高阶函数的例子,但通常不被认为是有用的编程结构。在这里,我们看看基于Y组合器和包装器的编程技术如何让程序员对函数的内部工作进行控制,而不需要重写和重新编译代码。作为一个实验,使用这种技术来实现类型推理算法W,以便在对算法的干扰最小的情况下产生错误消息。该示例程序的代码说明了这些概念的真正用处以及它们可以轻松应用的方式。还讨论了许多其他实现技术和可能的应用,包括使用高阶函数来模拟异常和延续的使用。

这是一篇很棒的论文。任何对函数式编程感兴趣的人都可能喜欢阅读它。

I've been reading a bit lately about functional programming and I am trying to grok the Y-Combinator. I understand that you can use the Y-Combinator to effectively implement recursion in a language that doesn't support recursion directly. However, every language that I'm likely to use already supports recursion so I'm not sure how useful it would be to use the Y-Combinator for that.

Is there a better practical example of Y-Combinator usage that I'm missing? Has anyone actually used one in real production code? Or is using the Y-Combinator really just a mind-bending academic exercise (albeit a pretty cool one).

解决方案

I'm going to disagree with other answers: The fixed-point (Y) combinator does have practical applications, but it takes a very imaginative mind to find them. Like Bruce McAdam. Here's the abstract from his paper That About Wraps it Up:

The Y combinator for computing fixed points can be expressed in Standard ML. It is frequently used as an example of the power of higher-order functions, but is not generally regarded as a useful programming construction. Here, we look at how a programming technique based on the Y combinator and wrappers can give programmers a level of control over the internal workings of functions not otherwise possible without rewriting and recompiling code. As an experiment, the type-inference algorithm W is implemented using this technique, so that error messages are produced with minimum interference to the algorithm. The code for this example program illustrates the genuine usefulness of the concepts and the ease with which they can be applied. A number of other implementation techniques and possible applications are also discussed, including the use of higher-order functions to simulate the use of exceptions and continuations.

It's a great paper; anyone interested in functional programming will probably enjoy reading it.

这篇关于Y-Combinator实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆