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.
KeywordsRecursive Function Recursive Call Program Transformation Proof Tree Calculation Rule
Unable to display preview. Download preview PDF.
- 1.Bird, R., de Moor, O.: Algebra of Programming. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1996)Google Scholar
- 3.Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)Google Scholar
- 8.Bird, R.: Introduction to Functional Programming using Haskell. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1998)Google Scholar
- 10.Morihata, A.: Relationship between arguments and results of recursive functions. Master’s thesis. University of Tokyo (2006)Google Scholar
- 11.Chin, W.N.: Fully lazy higher-order removal. In: Proc. of 1992 ACM SIGPLAN Wksh. on Partial Evaluation and Semantics-Based Program Manipulation, PEPM 1992. TR YALEU/DCS/RR-909, Yale University, pp. 38–47 (1992)Google Scholar
- 13.Morihata, A., Kakehi, K., Hu, Z., Takeichi, M.: IO swapping leads you there and back again. In: Rutherford, M.J. (ed.) Proc. of 7th GPCE Young Researchers Wksh., GPCE-YRW 2005, pp. 7–13. Inst. of Cybernetics, Tallinn (2005); Extended abstract of Google Scholar
- 14.Morihata, A., Kakehi, K., Hu, Z., Takeichi, M.: Reversing iterations: IO swapping leads you there and back again. Techn. Report METR 2005-11, Dept. of Mathematical Informatics, University of Tokyo (2005)Google Scholar