arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2302.10049cs.PL
收藏

可逆函数的尾递归转换

Tail recursion transformation for invertible functions

Joachim Tilsted Kristensen, Robin Kaarsgaard, Michael Kirkedal Thomsen

AI总结:

针对可逆编程中CPS转换的局限性,提出一种专门针对可逆函数的尾递归转换算法,通过定制数据类型将可逆递归函数转换为一对尾递归函数,从而实现尾递归逆函数的直接提取。

摘要:

尾递归函数比一般递归函数允许更广泛的优化。因此,大量研究致力于这类函数的转换与优化,特别是以续体传递风格(CPS)编写的函数。尽管CPS转换能够将任何递归函数转换为等价的尾递归函数,但它在可逆编程的语境中存在严重问题(因为它依赖于高阶函数等麻烦的特性),我们主张将(局部)可逆性放宽为(全局)可逆性可以极大改善这一状况。在此基础上,我们提出了一种专门针对可逆函数的尾递归转换算法。其关键洞察是,由保持可逆性的程序转换所引入的函数,只需在作为转换对象的函数调用它们的上下文中是可逆的。我们展示了如何使用对应于此类上下文的定制数据类型,将可逆递归函数转换为一对作用于该上下文的尾递归函数,其中调用被突出显示,并且可以从中直接提取出尾递归逆函数。

英文摘要:

Tail recursive functions allow for a wider range of optimisations than general recursive functions. For this reason, much research has gone into the transformation and optimisation of this family of functions, in particular those written in continuation passing style (CPS). Though the CPS transformation, capable of transforming any recursive function to an equivalent tail recursive one, is deeply problematic in the context of reversible programming (as it relies on troublesome features such as higher-order functions), we argue that relaxing (local) reversibility to (global) invertibility drastically improves the situation. On this basis, we present an algorithm for tail recursion conversion specifically for invertible functions. The key insight is that functions introduced by program transformations that preserve invertibility, need only be invertible in the context in which the functions subject of transformation calls them. We show how a bespoke data type, corresponding to such a context, can be used to transform invertible recursive functions into a pair of tail recursive function acting on this context, in a way where calls are highlighted, and from which a tail recursive inverse can be straightforwardly extracted.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑