Our aim here is to illustrate how the benefits of structural corecursion can be found in a broader swath of the programming landscape than previously thought. Beginning from a tutorial on structural corecursion in the total, pure functional language Agda, we show how these same ideas are mapped to familiar concepts in a variety of different languages. We show how corecursion can be done in strict functional languages like Scheme, and even escapes the functional paradigm entirely, showing up in the natural expression of common object-oriented features found in languages like Python and Java. Opening up structural corecursion to a much wider selection of languages and paradigms -- and therefore, also to a much larger audience of programmers -- lets us also ask how corecursion interacts with computational effects. Of note, we demonstrate that combining structural corecursion with effects can increase its expressive power. We show a classical version of corecursion -- using first-class control made possible by Scheme's classical call/cc -- that enables us to write some new stream-processing algorithms that aren't possible in effect-free languages.
翻译:我们在这里的目的是要说明结构核心是如何在比以前想象的更广泛的编程景观中找到结构核心的好处的。从关于结构核心的辅导开始,我们从总体的纯功能语言阿格达语开始,我们展示这些相同的想法是如何被映射为不同语言的熟悉概念的。我们展示了如何以严格的功能语言,例如“计划”进行核心化,甚至完全摆脱了功能范式,在Python和爪哇等语言中发现的共同目标导向特征的自然表达中显示出了这种核心化的好处。打开结构核心化,让更多的语言和范例选择,因此,也让更多的程序员观众了解这些结构核心化如何与计算效果发生互动。值得注意的是,我们展示了结构核心化与效果相结合可以增加其表达力。我们展示了典型的“核心”版本,使用“计划”的经典呼叫/cc 所允许的一流控制,使我们能够写出一些在实际上不可能的“自由语言”的新的流处理算法。