Lightweight fusion by fixed point promotion

This paper proposes a lightweight fusion method for general recursive function definitions. Compared with existing proposals, our method has several significant practical features: it works for general recursive functions on general algebraic data types; it does not produce extra runtime overhea (except for possible code size increase due to the success of fusion); and it is readily incorporated in standard inlining optimization. This is achieved by extending the ordinary inlining process with a new fusion law that transforms a term of the form f o (fixgλx.E) to a new fixed point term fixhλx.E′ by promoting the function f through the fixed point operator. This is a sound syntactic transformation rule that is not sensitive to the types of f and g. This property makes our method applicable to wide range of functions including those with multi-parameters in both curried and uncurried forms. Although this method does not guarantee any form of completeness, it fuses typical examples discussed in the literature and others that involve accumulating parameters, either in the tt foldl-like specific forms or in general recursive forms, without any additional machinery. In order to substantiate our claim, we have implemented our method in a compiler. Although it is preliminary, it demonstrates practical feasibility of this method.

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

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

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

[4]  Eelco Visser,et al.  Warm fusion in Stratego: A case study in generation of program transformation systems , 2004, Annals of Mathematics and Artificial Intelligence.

[5]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1988, Theoretical Computer Science.

[6]  Simon L. Peyton Jones,et al.  A short cut to deforestation , 1993, FPCA '93.

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

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

[9]  Patricia Johann,et al.  Monadic augment and generalised short cut fusion , 2007, J. Funct. Program..

[10]  Manuel M. T. Chakravarty,et al.  Functional array fusion , 2001, ICFP '01.

[11]  Masahito Hasegawa,et al.  Axioms for Recursion in Call-by-Value , 2001, High. Order Symb. Comput..

[12]  Wei-Ngan Chin Safe fusion of functional expressions , 1992, LFP '92.

[13]  Shin-ya Katsumata,et al.  Algebraic fusion of functions with an accumulating parameter and its improvement , 2008, J. Funct. Program..

[14]  Josef Svenningsson Shortcut fusion for accumulating parameters & zip-like functions , 2002, ICFP '02.

[15]  Olaf Chitil,et al.  Typer inference builds a short cut to deforestation , 1999, ICFP '99.

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

[17]  Tanaka Jiro Report on APCHI '98 , 2000 .

[18]  Simon Peyton Jones,et al.  Playing by the rules: rewriting as a practical optimisation technique in GHC , 2001 .

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

[20]  David Sands Proving the Correctness of Recursion-Based Automatic Program Transformations , 1995, TAPSOFT.

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