Factorising folds for faster functions

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.

[1]  Erik Poll,et al.  Algebra of Programming by Richard Bird and Oege de Moor, Prentice Hall, 1996 (dated 1997). , 1999 .

[2]  Grant Malcolm,et al.  Algebraic Data Types and Program Transformation , 1990 .

[3]  Nils Anders Danielsson,et al.  Fast and loose reasoning is morally correct , 2006, POPL '06.

[4]  C. A. R. Hoare,et al.  Proof of correctness of data representations , 1972, Acta Informatica.

[5]  Graham Hutton,et al.  Calculating an exceptional machine , 2004, Trends in Functional Programming.

[6]  Mauro Jaskelioff,et al.  Modular Monad Transformers , 2009, ESOP.

[7]  Simon L. Peyton Jones,et al.  Unboxed Values as First Class Citizens in a Non-Strict Functional Language , 1991, FPCA.

[8]  Maarten M. Fokkinga,et al.  Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire , 1991, FPCA.

[9]  Patricia Johann,et al.  Foundations for structured programming with GADTs , 2008, POPL '08.

[10]  John Hughes,et al.  A Novel Representation of Lists and its Application to the Function "reverse" , 1986, Inf. Process. Lett..

[11]  Roland Carl Backhouse,et al.  Generic Programming: An Introduction , 1998, Advanced Functional Programming.

[12]  Graham Hutton,et al.  Programming in Haskell , 2007 .

[13]  Alexander A. Stepanov,et al.  Generic Programming , 1988, ISSAC.

[14]  Janis Voigtländer,et al.  Asymptotic Improvement of Computations over Free Monads , 2008, MPC.

[15]  Simon L. Peyton Jones,et al.  Practical type inference for arbitrary-rank types , 2007, Journal of Functional Programming.

[16]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[17]  Graham Hutton,et al.  A tutorial on the universality and expressiveness of fold , 1999, Journal of Functional Programming.

[18]  Paul Hudak,et al.  Monad transformers and modular interpreters , 1995, POPL '95.

[19]  VytiniotisDimitrios,et al.  Simple unification-based type inference for GADTs , 2006 .

[20]  G. Malcolm,et al.  Data Structures and Program Transformation , 1990, Sci. Comput. Program..

[21]  Jeremy Gibbons,et al.  Fission for Program Comprehension , 2006, MPC.

[22]  Richard S. Bird,et al.  Algebra of programming , 1997, Prentice Hall International series in computer science.

[23]  Graham Hutton,et al.  The worker/wrapper transformation , 2009, Journal of Functional Programming.

[24]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[25]  Christine Paulin-Mohring,et al.  Proceedings of the 9th international conference on Mathematics of Program Construction , 2008 .