Shortcut fusion rules for the derivation of circular and higher-order monadic programs

Functional programs often combine separate parts using intermediate data structures for communicating results. These programs are modular, easier to understand and maintain, but suffer from inefficiencies due to the generation of those gluing data structures. To eliminate such redundant data structures, some program transformation techniques have been proposed. One such technique is shortcut fusion, and has been studied in the context of both pure and monadic functional programs. Recently, we have extended standard shortcut fusion: in addition to intermediate structures, the program parts may now communicate context information, and it still is possible to eliminate those structures. This is achieved by transforming the original function composition into a circular program. This new technique, however, has been studied in the context of purely functional programs only. In this paper, we propose an extension to this new form of fusion, but in the context of monadic programming: we derive monadic circular programs from strict ones, maintaining the global effects. Later, the circularities in the derived programs are traded by high-order definitions, using a well-known program transformation technique. We finally obtain very efficient deforested programs. An important feature of our extensions is that they can be uniformly defined for a wide class of data types and monads, using generic calculation rules.

[1]  S. Doaitse Swierstra,et al.  Linear, bounded, functional pretty-printing , 2009, J. Funct. Program..

[2]  Graham Hutton,et al.  Monadic parsing in Haskell , 1998, Journal of Functional Programming.

[3]  Anthony M. Sloane,et al.  Generating software from specifications , 2007 .

[4]  Jeremy Gibbons,et al.  Linear−time Breadth−first Tree Algorithms: An Exercise in the Arithmetic of Folds and Zips , 1993 .

[5]  Richard S. Bird,et al.  Introduction to functional programming using haskeu , 1998 .

[6]  Eric Johnson,et al.  Tool Demonstration: Silver Extensible Compiler Frameworks and Modular Language Extensions for Java and C , 2006, 2006 Sixth IEEE International Workshop on Source Code Analysis and Manipulation.

[7]  Chris Okasaki,et al.  Breadth-first numbering: lessons from a small exercise in algorithm design , 2000, ICFP '00.

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

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

[10]  Jukka Paakki,et al.  Attribute grammar paradigms—a high-level methodology in language implementation , 1995, CSUR.

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

[12]  Julia L. Lawall Implementing Circularity Using Partial Evaluation , 2001, PADO.

[13]  Ralf Hinze,et al.  Generic Haskell: practice and theory , 2003 .

[14]  John Launchbury,et al.  A recursive do for Haskell , 2002, Haskell '02.

[15]  Isao Sasano,et al.  Lightweight fusion by fixed point promotion , 2007, POPL '07.

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

[17]  João Paulo Sousa Ferreira Fernandes Design, implementation and calculation of circular programs , 2009 .

[18]  Richard S. Bird,et al.  Introduction to functional programming , 1988, Prentice Hall International series in computer science.

[19]  Neil Ghani,et al.  Short Cut Fusion of Recursive Programs with Computational Effects , 2008 .

[20]  Thomas Johnsson,et al.  Attribute grammars as a functional programming paradigm , 1987, FPCA.

[21]  Olaf Chitil,et al.  Type-inference based deforestation of functional programs , 2000 .

[22]  PaakkiJukka Attribute grammar paradigmsa high-level methodology in language implementation , 1995 .

[23]  R. Cockett,et al.  Strong categorical datatypes I , 1991 .

[24]  Simon Peyton Jones,et al.  The New GHC/Hugs Runtime System , 1998 .

[25]  Alberto Pardo Generic Accumulations , 2002, Generic Programming.

[26]  João Saraiva,et al.  Tools and libraries to model and manipulate circular programs , 2007, PEPM '07.

[27]  Samson Abramsky,et al.  Domain theory , 1995, LICS 1995.

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

[29]  Richard S. Bird Using circular programs to eliminate multiple traversals of data , 2004, Acta Informatica.

[30]  S. Doaitse Swierstra,et al.  Typing Haskell with an Attribute Grammar , 2004, Advanced Functional Programming.

[31]  Olivier Danvy,et al.  There and Back Again , 2005, Fundam. Informaticae.

[32]  Roland Carl Backhouse,et al.  Algebraic and Coalgebraic Methods in the Mathematics of Program Construction , 2000, Lecture Notes in Computer Science.

[33]  S. D. Swierstra,et al.  Using attribute grammars to derive efficient functional programs , 1986 .

[34]  Janis Voigtländer Semantics and Pragmatics of New Shortcut Fusion Rules , 2008, FLOPS.

[35]  Janis Voigtländer Using circular programs to deforest in accumulating parameters , 2002, ASIA-PEPM '02.

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

[37]  Andrzej Skowron,et al.  The Power of the Lambda Abstraction Strategy for Program Derivation , 1989, J. Inf. Process. Cybern..

[38]  Jeremy Gibbons,et al.  Calculating Functional Programs , 2000, Algebraic and Coalgebraic Methods in the Mathematics of Program Construction.

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

[40]  João Saraiva,et al.  Generating Spreadsheet-Like Tools from Strong Attribute Grammars , 2003, GPCE.

[41]  Masato Takeichi,et al.  A calculational fusion system HYLO , 1997, Algorithmic Languages and Calculi.

[42]  Alberto Pardo A calculational approach to recursive programs with effects / von Albert Pardo , 2001 .

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

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

[45]  Simon L. Peyton Jones,et al.  Aspect-Oriented Compilers , 1999, GCSE.

[46]  Patricia Johann,et al.  Short Cut Fusion for Effects , 2008, Trends in Functional Programming.

[47]  Patricia Johann,et al.  Free theorems in the presence of seq , 2004, POPL.

[48]  Uwe Kastens,et al.  The Eli System , 1998, CC.

[49]  Akihiko Takano,et al.  Shortcut Deforestation in Calculational Form(Theory of Rewriting Systems and Its Applications) , 1995 .