The HERMIT in the stream: fusing stream fusion's concatMap

Stream Fusion, a popular deforestation technique in the Haskell community, cannot fuse the concatMap combinator. This is a serious limitation, as concatMap represents computations on nested streams. The original implementation of Stream Fusion used the Glasgow Haskell Compiler's user-directed rewriting system. A transformation which allows the compiler to fuse many uses of concatMap has previously been proposed, but never implemented, because the host rewrite system was not expressive enough to implement the proposed transformation. In this paper, we develop a custom optimization plugin which implements the proposed concatMap transformation, and study the effectiveness of the transformation in practice. We also provide a new translation scheme for list comprehensions which enables them to be optimized. Within this framework, we extend the transformation to monadic streams. Code featuring uses of concatMap experiences significant speedup when compiled with this optimization. This allows Stream Fusion to outperform its rival, foldr/build, on many list computations, and enables performance-sensitive code to be expressed at a higher level of abstraction.

[1]  Andy Gill,et al.  The HERMIT in the Tree - Mechanizing Program Transformations in the GHC Core Language , 2012, IFL.

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

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

[4]  Roman Leshchinskiy,et al.  Stream fusion: from lists to streams to nothing at all , 2007, ICFP '07.

[5]  Ralf Hinze,et al.  Implementation and Application of Functional Languages , 2012, Lecture Notes in Computer Science.

[6]  Hongbin Zheng,et al.  Polly – Polyhedral optimization in LLVM , 2012 .

[7]  Christian M. Reidys,et al.  Partition function and base pairing probabilities for RNA-RNA interaction prediction , 2009, Bioinform..

[8]  André L. M. Santos,et al.  Compilation by transformation in non-strict functional languages , 1995 .

[9]  Manuel M. T. Chakravarty,et al.  An llVM backend for GHC , 2010, Haskell.

[10]  Vikram S. Adve,et al.  LLVM: a compilation framework for lifelong program analysis & transformation , 2004, International Symposium on Code Generation and Optimization, 2004. CGO 2004..

[11]  Nicolas Frisby,et al.  The Kansas University rewrite engine - A Haskell-Embedded Strategic Programming Language with Custom Closed Universes , 2014, J. Funct. Program..

[12]  Simon L. Peyton Jones,et al.  Exploiting vector instructions with generalized stream fusio , 2013, ICFP.

[13]  Ralf Hinze,et al.  Theory and Practice of Fusion , 2010, IFL.

[14]  Simon L. Peyton Jones Call-pattern specialisation for Haskell programs , 2007, ICFP '07.

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

[16]  J. Y. Girard,et al.  Interpretation fonctionelle et elimination des coupures dans l'aritmetique d'ordre superieur , 1972 .

[17]  Peter F. Stadler,et al.  How to Multiply Dynamic Programming Algorithms , 2013, BSB.

[18]  Simon L. Peyton Jones,et al.  The Implementation of Functional Programming Languages , 1987 .

[19]  Ceriel J. H. Jacobs,et al.  Parsing Techniques - A Practical Guide , 2007, Monographs in Computer Science.

[20]  Simon L. Peyton Jones,et al.  System F with type equality coercions , 2007, TLDI '07.

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

[22]  Duncan Coutts,et al.  Stream fusion : practical shortcut fusion for coinductive sequence types , 2011 .

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

[24]  Christian Höner zu Siederdissen,et al.  Sneaking around concatMap: efficient combinators for dynamic programming , 2012, ICFP.

[25]  Simon L. Peyton Jones,et al.  Giving Haskell a promotion , 2012, TLDI '12.

[26]  Will Partain,et al.  The nofib Benchmark Suite of Haskell Programs , 1992, Functional Programming.

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

[28]  J. Davenport Editor , 1960 .

[29]  Manuel M. T. Chakravarty,et al.  Data flow fusion with series expressions in Haskell , 2013, Haskell '13.

[30]  Ed Komp,et al.  The HERMIT in the machine: a plugin for the interactive transformation of GHC core language programs , 2012, Haskell.

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

[32]  Andy Gill,et al.  A Haskell Hosted DSL for Writing Transformation Systems , 2009, DSL.

[33]  Dan Klein,et al.  Joint Parsing and Alignment with Weakly Synchronized Grammars , 2010, NAACL.