Short Cut Fusion of Recursive Programs with Computational Effects

Fusion is the process of improving the efficiency of modularly constructed programs by transforming them into monolithic equivalents. This paper defines a generalization of the standard build combinator which expresses uniform production of functorial contexts containing data of inductive types. It also proves correct a fusion rule which generalizes the fold/ build and fold/buildp rules from the literature, and eliminates intermediate data structures of inductive types without disturbing the contexts in which they are situated. An important special case arises when this context is monadic. When it is, a second rule for fusing combinations of producers and consumers via monad operations, rather than via composition, is also available. We give examples illustrating both rules, and consider their coalgebraic duals as well. 21.1 GENERALIZING SHORT CUT FUSION 21.1.1 Introducing Short Cut Fusion Fusion is the process of improving the efficiency of modularly constructed programs by transforming them into monolithic equivalents. Short cut fusion [7] is concerned with eliminating list traversals from compositions of components that are “glued” together via intermediate lists. Short cut fusion uses a local transformation — known as the foldr/build rule — to fuse computations which can 1University of Nottingham, Nottingham, UK. nxg@cs.nott.ac.uk. Supported in part by EPSRC grant EP/C511964/2. 2Rutgers University, Camden, NJ, USA. pjohann@crab.rutgers.edu. Supported in part by NSF grant CCF-0700341.

[1]  Patricia Johann,et al.  Initial Algebra Semantics Is Enough! , 2007, TLCA.

[2]  Johan Jeuring,et al.  Merging Monads and Folds for Functional Programming , 1995, Advanced Functional Programming.

[3]  Ryu Hasegawa,et al.  Two applications of analytic functors , 2002, Theor. Comput. Sci..

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

[5]  I. G. BONNER CLAPPISON Editor , 1960, The Electric Power Engineering Handbook - Five Volume Set.

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

[7]  João Saraiva,et al.  A shortcut fusion rule for circular program calculation , 2007, Haskell '07.

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

[9]  Thorsten Altenkirch,et al.  Containers: Constructing strictly positive types , 2005, Theor. Comput. Sci..

[10]  Alberto Pardo,et al.  Fusion of recursive programs with computational effects , 2001, Theor. Comput. Sci..

[11]  Tarmo Uustalu,et al.  Monadic augment and generalised short cut fusion , 2005, ICFP '05.

[12]  Claus. Juergensen Using monads to fuse recursive programs , 2002 .

[13]  Tarmo Uustalu,et al.  Build, Augment and Destroy, Universally , 2004, APLAS.

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

[15]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[16]  Alberto Pardo,et al.  Shortcut Fusion of Monadic Programs , 2008, J. Univers. Comput. Sci..