Warm Fusion for the Masses: Detailing Virtual Data Structure Elimination in Fully Recursive Language

In functional programming, small programs are often combined to construct larger, more complex ones. The component reuse encouraged by this modular style of programming yields many bene ts, but, unfortunately, modular programs also tend to be less e cient than their monolithic counterparts. This is frequently due to the construction of intermediate data structures which \glue" together smaller program components into larger ones. Fusion is the process of removing intermediate data structures from modularly constructed programs. Two particularly successful approaches to achieving fusion in functional languages have emerged in recent years. The rst is a catamorphic fusion technique based on Malcolm's promotion theorems, while the second is a shortcut based on parametricity which fuses compositional programs via canned applications of traditional fold/unfold program transformation steps. Warm fusion combines these to arrive at a third fusion method, in which the potentially exponential application of catamorphic fusion is controlled. In essence, the method uses catamorphic fusion to preprocess programs written in the common recursive style into compositions to which the shortcut applies. The primary purpose of this paper is to report on a prototype implementation of the warm fusion method, together with the maturing of ideas from Launchbury and Sheard's paper ([LS95]) introducing the method that construction of the prototype has entailed. In particular, we treat warm fusion in the context of a fully polymorphic higher-order language, and so resolve an important outstanding issue raised in [LS95]. We also demonstrate that it can be automated to eliminate from programs intermediate data structures other than lists. Our implementation experience suggests that the development of a fully automated tool for fusing recursively de ned programs | suitable for incorporation into a state-of-the-art compiler | should be achievable. A secondary, but nevertheless fundamental, aim of this paper is to o er a detailed and self-contained treatment of the warm fusion method. We provide robust discussions of the historical and technical contexts out of which warm fusion has grown, and present the method in su cient detail to render this paper accessible to readers with modest background in functional programming, regardless of whether or not they have any prior familiarity with program fusion.

[1]  Maarten M. Fokkinga,et al.  Law and order in algorithmics , 1992 .

[2]  Robert Glück,et al.  A Roadmap to Metacomputation by Supercompilation , 1996, Dagstuhl Seminar on Partial Evaluation.

[3]  Glynn Winskel,et al.  Domain Theoretic Models of Polymorphism , 1989, Inf. Comput..

[4]  Todd A. Proebsting,et al.  Filter fusion , 1996, POPL '96.

[5]  Philip Wadler,et al.  When Will Deforestation Stop , 1988 .

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

[7]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[8]  Antony J. T. Davie An introduction to functional programming systems using Haskell , 1992 .

[9]  J. Girard Une Extension De ĽInterpretation De Gödel a ĽAnalyse, Et Son Application a ĽElimination Des Coupures Dans ĽAnalyse Et La Theorie Des Types , 1971 .

[10]  Richard C. Waters,et al.  Automatic transformation of series expressions into loops , 1991, TOPL.

[11]  John Launchbury,et al.  Warm fusion: deriving build-catas from recursive definitions , 1995, FPCA '95.

[12]  John Launchbury,et al.  Graph Algorithms with a Functional Flavous , 1995, Advanced Functional Programming.

[13]  Tatsuya Hagino,et al.  A categorical programming language , 2020, ArXiv.

[14]  Peter J. Freyd,et al.  Recursive types reduced to inductive types , 1990, [1990] Proceedings. Fifth Annual IEEE Symposium on Logic in Computer Science.

[15]  John C. Reynolds,et al.  Types, Abstraction and Parametric Polymorphism , 1983, IFIP Congress.

[16]  Tim Sheard,et al.  A fold for all seasons , 1993, FPCA '93.

[17]  Torben Amtoft Unfold/fold Transformations Preserving Termination Properties , 1992, PLILP.

[18]  J. Girard,et al.  Proofs and types , 1989 .

[19]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[20]  Grant Malcolm Homomorphisms and Promotability , 1989, MPC.

[21]  John C. Reynolds,et al.  Towards a theory of type structure , 1974, Symposium on Programming.

[22]  Johan Jeuring Theories for Algorithm Calculation , 1993 .

[23]  John Hughes,et al.  Why Functional Programming Matters , 1989, Comput. J..

[24]  Graham Hutton,et al.  Bananas in space: extending fold and unfold to exponential types , 1995, FPCA '95.

[25]  David Sands,et al.  Total correctness by local improvement in the transformation of functional programs , 1996, TOPL.

[26]  Richard C Waters Synchronizable Series Expressions. Part 1. User's Manual for the OSS Macro Package. , 1987 .

[27]  Masato Takeichi,et al.  Deriving structural hylomorphisms from recursive definitions , 1996, ICFP '96.

[28]  Andrew John Gill,et al.  Cheap deforestation for non-strict functional languages , 1996 .

[29]  Valentin F. Turchin,et al.  The concept of a supercompiler , 1986, TOPL.

[30]  Peter D. Mosses,et al.  Denotational semantics , 1995, LICS 1995.

[31]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1990, Theor. Comput. Sci..

[32]  John Darlington,et al.  A Transformation System for Developing Recursive Programs , 1977, J. ACM.

[33]  Richard C. Waters Obviously Synchronizable Series Expressions: Part I: User's Manual for the OSS Macro Package , 1987 .

[34]  Lambert Meertens,et al.  Algorithmics : towards programming as a mathematical activity , 1986 .

[35]  Simon David Marlow,et al.  Deforestation for higher-order functional programs , 1995 .

[36]  Robert Glück,et al.  Towards Unifying Partial Evaluation, Deforestation, Supercompilation, and GPC , 1994, ESOP.

[37]  Akihiko Takano,et al.  Shortcut deforestation in calculational form , 1995, FPCA '95.

[38]  Philip Wadler Listlessness is better than laziness II: composing listless functions , 1985, Programs as Data Objects.