一句话:用左右折叠等价性统一互推导直接风格、累加器与定界 CPS,并厘清其成立条件及列表 fold 参数顺序的影响。
论文研究左右折叠在 Peano 数与列表上的等价性,并用 Ohori 和 Sasano 的轻量融合与不动点提升,最小化地互推导三类程序:直接风格结构递归函数、带累加器的结构尾递归函数,以及定界续延传递风格(delimited CPS)的结构尾递归函数。论文给出等价成立的条件:Peano 数原始迭代下无条件成立;原始递归下模归纳步参数的左置换性;列表迭代或递归下若两个 fold 同类型也模左置换性。文章还回顾列表 fold 自 1980 年代以来归纳步参数交换的历史,指出不交换参数时 Bird 与 Wadler 的第二对偶定理更能体现 re-bracketing,而这是递归程序尾递归化的关键。
Abstract The equivalence of folding left and right over Peano numbers and lists makes it possible to minimalistically inter-derive (1) structurally recursive functions in direct style, (2) structurally tail-recursive functions that use an accumulator, and (3) structurally tail-recursive functions in delimited continuation-passing style, using Ohori and Sasano’s lightweight fusion by fixed-point promotion. When the fold-left and the fold-right functions account for primitive iteration for Peano numbers, this equivalence is unconditional. When they account for primitive recursion for Peano numbers, this equivalence is modulo left permutativity of their induction-step parameter – a property which is more general than associativity and commutativity. And when they account for primitive iteration or for primitive recursion over lists, this equivalence is modulo left permutativity of their induction-step parameter if these two fold functions have the same type. Since the 1980s, however, the two fold functions for lists do not have the same type: the arguments for their induction-step parameter are swapped, a re-ordering that complicated Bird and Wadler’s duality theorems and whose history is reviewed in an appendix. Without this re-ordering, Bird and Wadler’s second duality theorem more visibly accounts for “re-bracketing,” which is a key step to make recursive programs tail recursive in the general area of program development, from Cooper in the 1960s and onwards.