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.
翻译:尾部递归函数允许比一般递归函数更广泛的优化功能。 因此,许多研究已经进入了功能组合的转化和优化, 特别是那些在继续传递样式( CPS) 中写成的函数。 虽然 CPS 转换能够将任何递转函数转换成等尾部递回函数, 在可逆编程( 因为它依赖于高阶函数等麻烦特征) 的背景下, 问题很大( 因为它依赖高阶函数), 我们争辩说, 放松( 本地) 递转功能到( 全球) 倒置功能会大大改善这种情况。 基于这个原因, 我们提出了尾部递转转换的算法, 特别是不可逆函数。 关键洞察力是, 程序变换的函数所引入的功能, 只有在转换函数调用它们时, 才会不可视而不见。 我们表明, 如何使用一种与此环境相对应的表态数据类型, 来将不可逆的递归回函数转换成对立的尾部递回函数, 在这种背景下, 以突出调的方式, 和从此尾部递转成直截为可解的函数。