Hostname: page-component-8448b6f56d-42gr6 Total loading time: 0 Render date: 2024-04-23T05:54:15.426Z Has data issue: false hasContentIssue false

Factorising folds for faster functions

Published online by Cambridge University Press:  30 June 2010

GRAHAM HUTTON
Affiliation:
University of Nottingham, Nottingham, UK (e-mail: gmh@cs.nott.ac.uk)
MAURO JASKELIOFF
Affiliation:
Universidad Nacional de Rosario, Rosario, Argentina (e-mail: mauro@fceia.unr.edu.ar)
ANDY GILL
Affiliation:
University of Kansas, Lawrence, KS, USA (e-mail: andygill@ku.edu)
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.

The worker/wrapper transformation is a general technique for improving the performance of recursive programs by changing their types. The previous formalisation (A. Gill & G. Hutton, J. Funct. Program., vol. 19, 2009, pp. 227–251) was based upon a simple fixed-point semantics of recursion. In this paper, we develop a more structured approach, based upon initial-algebra semantics. In particular, we show how the worker/wrapper transformation can be applied to programs defined using the structured pattern of recursion captured by fold operators, and illustrate our new technique with a number of examples.

Type
Articles
Copyright
Copyright © Cambridge University Press 2010

References

Backhouse, R., Jansson, P., Jeuring, J. & Meertens, L. (1999) Generic programming: An introduction. In Advanced Functional Programming, Swierstra, D., Henriques, P. & Oliveira, J. (eds), LNCS 1608. Springer-Verlag, Berlin, pp. 28115.Google Scholar
Bird, R. & de Moor, O. (1997) Algebra of Programming. Prentice-Hall, Englewood Cliffs, NJ.Google Scholar
Danielsson, N. A., Gibbons, J., Hughes, J. & Jansson, P. (2006) Fast and loose reasoning is morally correct. In Principles of Programming Languages. ACM Press, New York.Google Scholar
Gibbons, J. (2006) Fission for program comprehension. In Mathematics of Program Construction, Uustalu, T. (ed), Lecture Notes in Computer Science, vol. 4014. Springer-Verlag, Berlin, pp. 162179.CrossRefGoogle Scholar
Gill, A. & Hutton, G. (2009) The worker/wrapper transformation, J. Funct. Program., 19 (2): 227251.Google Scholar
Hoare, T. (1972) Proof of correctness of data representations, Acta Inform., 1 (4): 271281.Google Scholar
Hughes, J. (1986) A novel representation of lists and its application to the function reverse, Inf. Process. Lett., 22 (3): 141144.CrossRefGoogle Scholar
Hutton, G. (1999) A tutorial on the universality and expressiveness of fold. J. Funct. Program., 9 (4): 355372.CrossRefGoogle Scholar
Hutton, G. (2007) Programming in Haskell. Cambridge University Press, Cambridge, UK.CrossRefGoogle Scholar
Hutton, G. & Wright, J. (2006) Calculating an exceptional machine. In Trends in Functional Programming, vol. 5, Loidl, H.-W. (ed), Intellect, UK. Selected papers from the Fifth Symposium on Trends in Functional Programming, Munich, Germany, November 2004.Google Scholar
Jaskelioff, M. (2009) Modular monad transformers. In Proceedings of the European Symposium on Programming. LNCS, vol. 5502. Springer-Verlag, Berlin, pp. 6479.Google Scholar
Johann, P. & Ghani, N. (2008) Foundations for structured programming with GADTs. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM Press, New York, pp. 297308.Google Scholar
Liang, S., Hudak, P. & Jones, M. (1995) Monad transformers and modular interpreters. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM Press, New York, pp. 333343.Google Scholar
Malcolm, G. (1990) Algebraic data types and program transformation. Sci. Comput. Program., 14 (2–3): 255280.CrossRefGoogle Scholar
Meijer, E., Fokkinga, M. & Paterson, R. (1991) Functional programming with bananas, lenses, envelopes and barbed wire. In Proceedings of the Conference on Functional Programming and Computer Architecture, Hughes, J. (ed), LNCS, vol. 523. Springer-Verlag, Berlin.Google Scholar
Peyton Jones, S. (2003) Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge, UK. Available at: www.haskell.org/definitionGoogle Scholar
Peyton Jones, S. & Launchbury, J. (1991) Unboxed values as first class citizens in a non-strict functional language. In Proceedings of the Conference on Functional Programming and Computer Architecture. Cambridge, MA: Springer-Verlag, Berlin.Google Scholar
Peyton Jones, S., Vytiniotis, D., Weirich, S. & Washburn, G. (2006) Simple unification-based type inference for GADTs. In Proceedings of the 11th ACM SIGPLAN International Conference on Functional Programming. ACM Press, New York, pp. 5061.Google Scholar
Peyton Jones, S., Vytiniotis, D., Weirich, S. & Shields, M. (2007) Practical type inference for arbitrary-rank types. J. Funct. Program., 17 (1): 182.Google Scholar
Voigtländer, J. (2008) Asymptotic improvement of computations over free monads. In Proceedings of the 9th International Conference on Mathematics of Program Construction. LNCS, vol. 5133. Marseille, France: Springer-Verlag, Berlin, pp. 388403.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.