Swapping Arguments and Results of Recursive Functions

Many useful calculation rules, such as fusion and tupling, rely on well-structured functions, especially in terms of inputs and outputs. For instance, fusion requires that well-produced outputs should be connected to well-consumed inputs, so that unnecessary intermediate data structures can be eliminated. These calculation rules generally fail to work unless functions are well-structured. In this paper, we propose a new calculation rule called IO swapping. IO swapping exchanges call-time computations (occurring in the arguments) and return-time computations (occurring in the results) of a function, while guaranteeing that the original and resulting function compute the same value. IO swapping enables us to rearrange inputs and outputs so that the existing calculation rules can be applied. We present new systematic derivations of efficient programs for detecting palindromes, and a method of higher-order removal that can be applied to defunctionalize function arguments, as two concrete applications.

[1]  F. Jones There and back again , 1989, Nature.

[2]  Akimasa Morihata,et al.  IO Swapping Leads You There And Back Again (Extended Abstract) , 2005 .

[3]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[4]  Akihiko Takano,et al.  Tupling calculation eliminates multiple data traversals , 1997, ICFP '97.

[5]  Armin Kühnemann,et al.  Comparison of Deforestation Techniques for Functional Programs and for Tree Transducers , 1999, Fuji International Symposium on Functional and Logic Programming.

[6]  Maarten M. Fokkinga,et al.  Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire , 1991, FPCA.

[7]  Richard S. Bird,et al.  Algebraic Identities for Program Calculation , 1989, Comput. J..

[8]  Janis Voigtländer Using circular programs to deforest in accumulating parameters , 2002, ASIA-PEPM '02.

[9]  Eerke A. Boiten,et al.  Improving Recursive Functions by Inverting the Order of Evaluation , 1992, Sci. Comput. Program..

[10]  Akimasa Morihata,et al.  Reversing Iterations: IO Swapping Leads You There And Back Again , 2005 .

[11]  Didier Parigot,et al.  Declarative Program Transformation: A Deforestation Case-Study , 1999, PPDP.

[12]  R. Bird Introduction to functional programming using Haskell, Second Edition , 1998 .

[13]  Masato Takeichi,et al.  Deriving structural hylomorphisms from recursive definitions , 1996, ICFP '96.

[14]  John C. Reynolds Definitional Interpreters for Higher-Order Programming Languages , 1998, High. Order Symb. Comput..

[15]  Wei-Ngan Chin Fully Lazy Higher-Order Removal , 1992, PEPM.

[16]  Donald E. Knuth,et al.  Semantics of context-free languages , 1968, Mathematical systems theory.

[17]  Alberto Pettorossi,et al.  Rules and strategies for transforming functional and logic programs , 1996, CSUR.

[18]  Wei-Ngan Chin Towards an automated tupling strategy , 1993, PEPM '93.

[19]  Richard S. Bird,et al.  Algebra of programming , 1997, Prentice Hall International series in computer science.

[20]  Richard S. Bird,et al.  Introduction to functional programming , 1988, Prentice Hall International series in computer science.

[21]  Richard S. Bird Using circular programs to eliminate multiple traversals of data , 2004, Acta Informatica.

[22]  Armin Kühnemann,et al.  Benefits of Tree Transducers for Optimizing Functional Programs , 1998, FSTTCS.

[23]  Erik Poll,et al.  Algebra of Programming by Richard Bird and Oege de Moor, Prentice Hall, 1996 (dated 1997). , 1999 .

[24]  Susumu Nishimura Fusion with stacks and accumulating parameters , 2004, PEPM '04.

[25]  Akimasa Morihata,et al.  MATHEMATICAL ENGINEERING TECHNICAL REPORTS Reversing Iterations: IO Swapping Leads You There And Back Again , 2005 .

[26]  Robert Giegerich,et al.  Attribute coupled grammars , 1984, SIGPLAN '84.