Hostname: page-component-586b7cd67f-2plfb Total loading time: 0 Render date: 2024-11-25T04:31:03.287Z Has data issue: false hasContentIssue false

Manipulating accumulative functions by swapping call-time and return-time computations*

Published online by Cambridge University Press:  08 May 2012

AKIMASA MORIHATA
Affiliation:
Tohoku University, Sendai, Japan (e-mail: [email protected])
KAZUHIKO KAKEHI
Affiliation:
University of Tokyo, Tokyo, Japan
ZHENJIANG HU
Affiliation:
National Institute of Informatics, Chiyoda, Tokyo, Japan
MASATO TAKEICHI
Affiliation:
National Institution for Academic Degrees and University Evaluation, Kodaira-shi, Tokyo, Japan
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Functional languages are suitable for transformational developments of programs. However, accumulative functions, or in particular tail-recursive functions, are known to be less suitable for manipulation. In this paper, we propose a program transformation named “IO swapping” that swaps call-time and return-time computations. It moves computations in accumulative parameters to results and thereby enables interesting transformations. We demonstrate effectiveness of IO swapping by several applications: deforestation, higher order removal, program inversion, and manipulation of circular programs.

Type
Articles
Copyright
Copyright © Cambridge University Press 2012

References

Backhouse, R. C., Jansson, P., Jeuring, J. & Meertens, L. G. L. T. (1999) Generic programming: An introduction. In Advanced Functional Programming, Third International School, Braga, Portugal, Revised Lectures. Lecture Notes in Computer Science, 1608, pp. 28115. Berlin, Germany: Springer-Verlag.Google Scholar
Bird, R. S. (1984) Using circular programs to eliminate multiple traversals of data. Acta Inf. 21, 239250.CrossRefGoogle Scholar
Bird, R. S. & Wadler, P. (1989) Introduction to Functional Programming. Saddle River, NJ: Prentice-Hall.Google Scholar
Boiten, E. A. (1992) Improving recursive functions by inverting the order of evaluation. Sci. Comput. Program. 18 (2), 139179.CrossRefGoogle Scholar
Boyer, R. S. & Moore, J. S. (1975) Proving theorems about Lisp functions. J. ACM. 22 (1), 129144.CrossRefGoogle Scholar
Boyer, R. S., Moore, J. S. & Shostak, R. E. (1976) Primitive recursive program transformations. In Proceedings of POPL'76: Conference Record of the Third ACM Symposium on Principles of Programming Languages, Atlanta, Georgia. Pittsburgh, PA: ACM Press, pp. 171174.CrossRefGoogle Scholar
Burstall, R. M. & Darlington, J. (1977) A transformation system for developing recursive programs. J. ACM. 24 (1), 4467.CrossRefGoogle Scholar
Chin, W.-N. (1994) Safe fusion of functional expressions II: Further improvements. J. Funct. Program. 4 (4), 515555.CrossRefGoogle Scholar
Correnson, L., Duris, É., Parigot, D. & Roussel, G. (1999) Declarative program transformation: A deforestation case-study. In Proceedings of International Conference on Principles and Practice of Declarative Programming (PPDP'99), Paris, France. Lecture Notes in Computer Science, vol. 1702. Berlin, Germany: Springer-Verlag, pp. 360377.Google Scholar
Danvy, O. & Goldberg, M. (2005) There and back again. Fundam. Inform. 66 (4), 397413.Google Scholar
Fernandes, J. P., Pardo, A. & Saraiva, J (2007) A shortcut fusion rule for circular program calculation. In Proceedings of the ACM SIGPLAN Workshop on Haskell (Haskell 2007), Freiburg, Germany. Pittsburgh, PA: ACM, pp. 95106.CrossRefGoogle Scholar
Fernandes, J. P. & Saraiva, J. (2007) Tools and libraries to model and manipulate circular programs. In Proceedings of the 2007 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Nice, France. Pittsburgh, PA: ACM, pp. 102111.Google Scholar
Fernandes, J. P., Saraiva, J., Seidel, D. & Voigtländer, J. (2011) Strictification of circular programs. In Proceedings of the 2011 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM 2011), Austin, TX, USA. Pittsburgh, PA: ACM, pp. 131140.Google Scholar
Giesl, J. (2000). Context-moving transformations for function verification. In Proceedings of the 9th International Workshop on Logic Programming Synthesis and Transformation (LOPSTR'99), selected papers. Lecture Notes in Computer Science, vol. 1817. Berlin, Germany: Springer-Verlag, pp. 293312.Google Scholar
Giesl, J., Kühnemann, A. & Voigtländer, J. (2007) Deaccumulation techniques for improving provability. J. Log. Algebr. Program. 71 (2), 79113.CrossRefGoogle Scholar
Gill, A. (1996) Cheap Deforestation for Non-Strict Functional Languages. PhD. thesis, Department of Computing Science, Glasgow University, Glasgow, UK.Google Scholar
Gill, A., Launchbury, J. & Peyton, Jones S. (1993) A short cut to deforestation. In Proceedings of FPCA'93 Conference on Functional Programming Languages and Computer Architecture, Copenhagen, Denmark. New York, NY: ACM Press, pp. 223232.Google Scholar
Glück, R. & Kawabe, M. (2005) A method for automatic program inversion based on LR(0) parsing. Fundam. Inform. 66 (4), 367395.Google Scholar
Katsumata, S. & Nishimura, S. (2008) Algebraic fusion of functions with an accumulating parameter and its improvement. J. Funct. Program. 18 (5–6), 781819.CrossRefGoogle Scholar
Kühnemann, A. (1998) Benefits of tree transducers for optimizing functional programs. In Proceedings of the 18th Conference on Foundations of Software Technology and Theoretical Computer Science, Chennai, India. Lecture Notes in Computer Science, vol. 1530. Berlin, Germany: Springer-Verlag, pp. 146157.CrossRefGoogle Scholar
Kühnemann, A. (1999) Comparison of deforestation techniques for functional programs and for tree transducers. In Proceedings of the 4th Fuji International Symposium on Functional and Logic Programming (FLOPS'99), Tukuba, Japan. Lecture Notes in Computer Science, vol. 1722. Berlin, Germany: Springer-Verlag, pp. 114130.CrossRefGoogle Scholar
Kühnemann, A., Glück, R. & Kakehi, K. (2001) Relating accumulative and non-accumulative functional programs. In Proceedings of the 12th International Conference on Rewriting Techniques and Applications (RTA 2001), Utrecht, the Netherlands. Lecture Notes in Computer Science, vol. 2051. Berlin, Germany: Springer-Verlag, pp. 154168.Google Scholar
Matsuda, K., Mu, S.-C., Hu, Z. & Takeichi, M. (2010) A grammar-based approach to invertible programs. In Proceedings of the 19th European Symposium on Programming Languages and Systems (ESOP 2010), held as part of the Joint European Conferences on Theory and Practice of Software (ETAPS 2010), Paphos, Cyprus. Lecture Notes in Computer Science, vol. 6012. Berlin, Germany: Springer-Verlag, pp. 448467.CrossRefGoogle Scholar
Meijer, E., Fokkinga, M. M. & Paterson, R. (1991) Functional programming with bananas, lenses, envelopes and barbed wire. In Proceedings of the 5th ACM Conference on Functional Programming Languages and Computer Architecture, Cambridge, MA, USA. Lecture Notes in Computer Science, vol. 523. Berlin, Germany: Springer-Verlag, pp. 124144.Google Scholar
Mogensen, T. Æ. (2006) Report on an implementation of a semi-inverter. In Proceedings of 6th International Andrei Ershov Memorial Conference on Perspectives of Systems Informatics (PSI 2006), Novosibirsk, Russia, revised papers. Lecture Notes in Computer Science, vol. 4378. Berlin, Germany: Springer-Verlag, pp. 322334.Google Scholar
Morihata, A. (2006) Relationship between Arguments and Results of Recursive Functions. Master's thesis, Graduate School of Information Science and Technology, University of Tokyo, Japan.CrossRefGoogle Scholar
Morihata, A., Kakehi, K., Hu, Z. & Takeichi, M. (2006) Swapping arguments and results of recursive functions. In Proceedings of the 8th International Conference on Mathematics of Program Construction (MPC 2006), Kuressaare, Estonia. Lecture Notes in Computer Science, vol. 4014. Berlin, Germany: Springer-Verlag, pp. 379396.Google Scholar
Nishimura, S. (2003) Correctness of a higher-order removal transformation through a relational reasoning. In Proceedings of the First Asian Symposium on Programming Languages and Systems (APLAS 2003), Beijing, China. Lecture Notes in Computer Science, vol. 2895. Berlin, Germany: Springer-Verlag, pp. 358375.CrossRefGoogle Scholar
Nishimura, S. (2004) Fusion with stacks and accumulating parameters. In Proceedings of the ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation (PEPM'04), Verona, Italy. New York, NY: ACM Press, pp. 101112.Google Scholar
Pardo, A., Fernandes, J. P. & Saraiva, J. (2009) Shortcut fusion rules for the derivation of circular and higher-order monadic programs. In Proceedings of the 2009 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation (PEPM 2009), Savannah, GA, USA. New York, NY: ACM Press, pp. 8190.CrossRefGoogle Scholar
Peyton, Jones S. (ed). (2003) Haskell 98 Language and Libraries: The Revised Report. Cambridge, UK: Cambridge University Press.Google Scholar
Roy, P. V. & Haridi, S. (2004) Concepts, Techniques, and Models of Computer Programming. Cambridge, MA: MIT Press.Google Scholar
Svenningsson, J. (2002) Shortcut fusion for accumulating parameters & zip-like functions. In Proceedings of the 7th ACM SIGPLAN International Conference on Functional Programming (ICFP'02), Pittsburgh, Pennsylvania, USA. New York, NY: ACM Press, pp. 124132.Google Scholar
Takano, A. & Meijer, E. (1995) Shortcut deforestation in calculational form. In Proceedings of SIGPLAN-SIGARCH-WG2.8 Conference on Functional Programming Languages and Computer Architecture (conference record of FPCA'95), La Jolla, CA, USA. New York, NY: ACM Press, pp. 306313.Google Scholar
Voigtländer, J. (2004) Using circular programs to deforest in accumulating parameters. Higher-Order Symb. Comput. 17 (1–2), 129163.CrossRefGoogle Scholar
Voigtländer, J. & Kühnemann, A. (2004) Composition of functions with accumulating parameters. J. Funct. Program. 14 (3), 317363.CrossRefGoogle Scholar
Wadler, P. (1990) Deforestation: Transforming programs to eliminate trees. Theor. Comput. Sci. 73 (2), 231248.CrossRefGoogle Scholar
Wand, M. (1980) Continuation-based program transformation strategies. J. ACM. 27 (1), 164180.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.