Skip to main content

Swapping Arguments and Results of Recursive Functions

  • Conference paper
Mathematics of Program Construction (MPC 2006)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 4014))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Bird, R., de Moor, O.: Algebra of Programming. Prentice Hall Int. Series in Computer Science. Prentice Hall, Englewood Cliffs (1996)

    Google Scholar 

  2. Bird, R.: Algebraic identities for program calculation. Computer J. 32(2), 122–126 (1989)

    Article  MathSciNet  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 

  4. Bird, R.: Using circular programs to eliminate multiple traversals of data. Acta Inform. 21, 239–250 (1984)

    Article  MATH  Google Scholar 

  5. 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)

    Chapter  Google Scholar 

  6. Pettorossi, A., Proietti, M.: Rules and strategies for transforming functional and logic programs. ACM Comput. Surveys 28(2), 360–414 (1996)

    Article  Google Scholar 

  7. 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)

    Chapter  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 

  9. 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)

    Chapter  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 

  12. 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)

    Chapter  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 [14]

    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 

  15. 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

    Article  MATH  Google Scholar 

  16. Danvy, O., Goldberg, M.: There and back again. Fund. Inform. 66(4), 397–413 (2005)

    MATH  MathSciNet  Google Scholar 

  17. 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)

    Chapter  Google Scholar 

  18. Ganzinger, H., Giegerich, R.: Attribute coupled grammars. In: Proc. of 1984 SIGPLAN Symp. on Compiler Construction, pp. 157–170. ACM Press, New York (1984)

    Chapter  Google Scholar 

  19. Knuth, D.E.: Semantics of context-free languages. Math. Syst. Theory 2(2), 127–145 (1968)

    Article  MATH  MathSciNet  Google Scholar 

  20. 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)

    Chapter  Google Scholar 

  21. 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)

    Chapter  Google Scholar 

  22. 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)

    Chapter  Google Scholar 

  23. Voigtländer, J.: Using circular programs to deforest in accumulating parameters. Higher-Order and Symb. Comput. 17(1-2), 129–163 (2004)

    Article  MATH  Google Scholar 

  24. Boiten, E.A.: Improving recursive functions by inverting the order of evaluation. Sci. of Comput. Programming 18(2), 139–179 (1992)

    Article  MATH  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics