Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Bird, R., de Moor, O.: Algebra of Programming. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1996)
Bird, R.: Algebraic identities for program calculation. Computer J. 32(2), 122–126 (1989)
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)
Bird, R.: Using circular programs to eliminate multiple traversals of data. Acta Inform. 21, 239–250 (1984)
Chin, W.N.: Towards an automated tupling strategy. In: Proc. of 1993 ACM SIGPLAN Symp. on Partial Evaluation and Semantics-Based Program Manipulation, PEPM 1993, pp. 119–132. ACM Press, New York (1993)
Pettorossi, A., Proietti, M.: Rules and strategies for transforming functional and logic programs. ACM Comput. Surveys 28(2), 360–414 (1996)
Hu, Z., Iwasaki, H., Takeichi, M., Takano, A.: Tupling calculation eliminates multiple data traversals. In: Proc. of 2nd ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 1997, pp. 164–175. ACM Press, New York (1997)
Bird, R.: Introduction to Functional Programming using Haskell. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1998)
Hu, Z., Iwasaki, H., Takeichi, M.: Deriving structural hylomorphisms from recursive definitions. In: Proc. of 1st ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 1996, pp. 73–82. ACM Press, New York (1996)
Morihata, A.: Relationship between arguments and results of recursive functions. Master’s thesis. University of Tokyo (2006)
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)
Danvy, O., Goldberg, M.: There and back again. In: Proc. of 7th ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 2002, pp. 230–234. ACM Press, New York (2002)
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 [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)
Reynolds, J.C.: Definitional interpreters for higher-order programming languages. Higher-Order and Symb. Comput. 11(4), 363–397 (1998); Reprinted from Proc. of 25th ACM Nat. Conf. (1972), with a foreword
Danvy, O., Goldberg, M.: There and back again. Fund. Inform. 66(4), 397–413 (2005)
Nishimura, S.: Fusion with stacks and accumulating parameters. In: Proc. of 2004 ACM SIGPLAN Wksh. on Partial Evaluation and Semantics-Based Program Manipulation, PEPM 2004, pp. 101–112. ACM Press, New York (2004)
Ganzinger, H., Giegerich, R.: Attribute coupled grammars. In: Proc. of 1984 SIGPLAN Symp. on Compiler Construction, pp. 157–170. ACM Press, New York (1984)
Knuth, D.E.: Semantics of context-free languages. Math. Syst. Theory 2(2), 127–145 (1968)
Kühnemann, A.: Benefits of tree transducers for optimizing functional programs. In: Arvind, V., Ramanujam, R. (eds.) FST TCS 1998. LNCS, vol. 1530, pp. 146–158. Springer, Heidelberg (1998)
Kühnemann, A.: Comparison of deforestation techniques for functional programs and for tree transducers. In: Middeldorp, A. (ed.) FLOPS 1999. LNCS, vol. 1722, pp. 114–130. Springer, Heidelberg (1999)
Correnson, L., Duris, E., Parigot, D., Roussel, G.: Declarative program transformation: A deforestation case-study. In: Nadathur, G. (ed.) PPDP 1999. LNCS, vol. 1702, pp. 360–377. Springer, Heidelberg (1999)
Voigtländer, J.: Using circular programs to deforest in accumulating parameters. Higher-Order and Symb. Comput. 17(1-2), 129–163 (2004)
Boiten, E.A.: Improving recursive functions by inverting the order of evaluation. Sci. of Comput. Programming 18(2), 139–179 (1992)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2006 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Morihata, A., Kakehi, K., Hu, Z., Takeichi, M. (2006). Swapping Arguments and Results of Recursive Functions. In: Uustalu, T. (eds) Mathematics of Program Construction. MPC 2006. Lecture Notes in Computer Science, vol 4014. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11783596_22
Download citation
DOI: https://doi.org/10.1007/11783596_22
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-35631-8
Online ISBN: 978-3-540-35632-5
eBook Packages: Computer ScienceComputer Science (R0)