skip to main content
10.1145/1291151.1291199acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
Article

Stream fusion: from lists to streams to nothing at all

Published:01 October 2007Publication History

ABSTRACT

This paper presents an automatic deforestation system, stream fusion, based on equational transformations, that fuses a wider range of functions than existing short-cut fusion systems. In particular, stream fusion is able to fuse zips, left folds and functions over nested lists, including list comprehensions. A distinguishing feature of the framework is its simplicity: by transforming list functions to expose their structure, intermediate values are eliminated by general purpose compiler optimisations.

We have reimplemented the Haskell standard List library on top of our framework, providing stream fusion for Haskell lists. By allowing a wider range of functions to fuse, we see an increase in the number of occurrences of fusion in typical Haskell programs. We present benchmarks documenting time and space improvements.

References

  1. Olaf Chitil. Type inference builds a short cut to deforestation. In ICFP '99: Proceedings of the fourth ACM SIGPLAN International Conference on Functional programming, pages 249--260, New York, NY, USA, 1999. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Olaf Chitil. Promoting non-strict programming. In Draft Proceedings of the 18th International Symposium on Implementation and Application of Functional Languages, IFL 2006, pages 512--516, Budapest, Hungary, September 2006. Eotvos Lorand University.Google ScholarGoogle Scholar
  3. Duncan Coutts, Don Stewart, and Roman Leshchinskiy. Rewriting Haskell strings. In Practical Aspects of Declarative Languages 8th International Symposium, PADL 2007, pages 50--64. Springer-Verlag, January 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Nils Anders Danielsson and Patrik Jansson. Chasing bottoms, a case study in program verification in the presence of partial and infinite values. In Dexter Kozen, editor, Proceedings of the 7th International Conference on Mathematics of Program Construction, MPC 2004, volume 3125 of LNCS, pages 85--109. Springer-Verlag, July 2004.Google ScholarGoogle Scholar
  5. Jeremy Gibbons. Streaming representation-changers. In D. Kozen, editor, Mathematics of Program Construction, pages 142--168. Springer-Verlag, 2004. LNCS 523.Google ScholarGoogle ScholarCross RefCross Ref
  6. Jeremy Gibbons and Geraint Jones. The under-appreciated unfold. In ICFP '98: Proceedings of the third ACM SIGPLAN International Conference on Functional programming, pages 273--279, New York, NY, USA, 1998. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Andrew Gill. Cheap Deforestation for Non-strict Functional Languages. PhD thesis, University of Glasgow, January 1996.Google ScholarGoogle Scholar
  8. Andrew Gill, John Launchbury, and Simon Peyton Jones. A shortcut to deforestation. In Conference on Functional Programming Languages and Computer Architecture, pages 223--232, June 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Zhenjiang Hu, Hideya Iwasaki, and Masato Takeichi. Deriving structural hylomorphisms from recursive definitions. In Proceedings 1st ACM SIGPLAN International Conference on Functional Programming, volume 31(6), pages 73--82. ACM Press, New York, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Patricia Johann. Short cut fusion: Proved and improved. In SAIG 2001: Proceedings of the Second International Workshop on Semantics, Applications, and Implementation of Program Generation, pages 47--71, London, UK, 2001. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Thomas Johnsson. Lambda lifting: transforming programs to recursive equations. In Functional programming languages and computer architecture. Proc. of a conference (Nancy, France, Sept.1985), New York, NY, USA, 1985. Springer-Verlag Inc. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. John Launchbury and Ross Paterson. Parametricity and unboxing with unpointed types. In European Symposium on Programming, pages 204--218, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. John Launchbury and Tim Sheard. Warm fusion: deriving build-catas from recursive definitions. In FPCA '95: Proceedings of the seventh international conference on Functional programming languages and computer architecture, pages 314--323, New York, NY, USA, 1995. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Erik Meijer, Maarten Fokkinga, and Ross Paterson. Functional programming with bananas, lenses, envelopes and barbed wire. In J. Hughes, editor, Proceedings 5th ACM Conf. on Functional Programming Languages and Computer Architecture, FPCA'91, Cambridge, MA, USA, 26-30 Aug 1991, volume 523, pages 124--144. Springer-Verlag, Berlin, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Will Partain. The nofib benchmark suite of Haskell programs. In Functional Programming, pages 195--202, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Simon Peyton Jones. Constructor Specialisation for Haskell Programs, 2007. Submitted for publication.Google ScholarGoogle Scholar
  17. Simon Peyton Jones and André L. M. Santos. A transformation-based optimiser for Haskell. Sci. Comput. Program., 32(1-3): 3--47, 1998. ISSN 0167-6423. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Simon Peyton Jones, Andrew Tolmach, and Tony Hoare. Playing by the rules: rewriting as a practical optimisation technique in GHC. In Ralf Hinze, editor, 2001 Haskell Workshop. ACM SIGPLAN, September 2001.Google ScholarGoogle Scholar
  19. Simon Peyton Jones et al. The Haskell 98 language and libraries: The revised report. Journal of Functional Programming, 13(1): 0--255, Jan 2003.Google ScholarGoogle Scholar
  20. Colin Runciman. SmallCheck 0.2: another lightweight testing library in Haskell. http://article.gmane.org/gmane.comp.lang.haskell.general/14461, 2006.Google ScholarGoogle Scholar
  21. Josef Svenningsson. Shortcut fusion for accumulating parameters & zip-like functions. In ICFP '02: Proceedings of the seventh ACM SIGPLAN International Conference on Functional programming, pages 124--132, New York, NY, USA, 2002. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Akihiko Takano and Erik Meijer. Shortcut deforestation in calculational form. In Conf. Record 7th ACM SIGPLAN/SIGARCH Int. Conf. on Functional Programming Languages and Computer Architecture, FPCA'95, pages 306--313. ACM Press, New York, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. The GHC Team. The Glasgow Haskell Compiler (GHC). http://haskell.org/ghc, 2007.Google ScholarGoogle Scholar
  24. Philip Wadler. List comprehensions. In Simon Peyton Jones, editor, The implementation of functional programming languages. Prentice Hall, 1987. Chapter 15.Google ScholarGoogle Scholar
  25. Philip Wadler. Deforestation: transforming programs to eliminate trees. Theoretical Computer Science, (Special issue of selected papers from 2nd European Symposium on Programming), 73(2):231--248, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Stream fusion: from lists to streams to nothing at all

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!