# Stream fusion : practical shortcut fusion for coinductive sequence types

@inproceedings{Coutts2011StreamF, title={Stream fusion : practical shortcut fusion for coinductive sequence types}, author={Duncan Coutts}, year={2011} }

In functional programming it is common practice to build modular programs by composing functions where the intermediate values are data structures such as lists or arrays. A desirable optimisation for programs written in this style is to fuse the composed functions and thereby eliminate the intermediate data structures and their associated runtime costs. Stream fusion is one such fusion optimisation that can eliminate intermediate data structures, including lists, arrays and other abstract data…

## Figures and Topics from this paper

## 11 Citations

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

- Computer SciencePEPM '14
- 2014

A custom optimization plugin is developed which implements the proposed concatMap transformation, and a new translation scheme for list comprehensions which enables them to be optimized, and extends the transformation to monadic streams.

Haskell Beats C Using Generalized Stream Fusion

- 2013

Stream fusion [3] is a powerful technique for automatically transforming high-level sequence-processing functions into efficient implementations. It has been used to great effect in Haskell libraries…

Type-Based Cost Analysis for Lazy Functional Languages

- Computer ScienceJournal of Automated Reasoning
- 2016

A type-based analysis employing amortisation and cost effects to statically determine upper bounds on evaluation costs of lazily evaluated functional languages, such as Haskell is applied.

Quoted staged rewriting: a practical approach to library-defined optimizations

- Computer Science
- 2017

This work introduces Quoted Staged Rewriting (QSR), an approach that uses type-safe, pattern matching-enabled quasiquotes to define optimizations and renders library-defined optimizations more practical than ever before.

Fold-Based Fusion as a Library

- Computer Science
- 2015

This paper presents an alternative approach, implementing fold-based fusion as a standalone library, using staging to compose operations on folds; the operations are partially evaluatedaway, yielding code that does not construct unnecessary inter-mediate data structures.

Call Arity

- Computer ScienceComput. Lang. Syst. Struct.
- 2018

Call Arity is an analysis that eta-expands functions based on their uses, instead of their definitions, and is very precise in the presence of recursion, which allows foldl-based combinators to take part in list fusion.

Fold-based fusion as a library: a generative programming pearl

- Computer ScienceScala@PLDI
- 2015

An alternative approach is presented, implementing fold-based fusion as a standalone library that uses staging to compose operations on folds, yielding code that does not construct unnecessary intermediate data structures.

Faster coroutine pipelines: A reconstruction

- Computer ScienceJournal of Functional Programming
- 2020

Using the same derivation steps, this paper is able to derive a similar encoding for a more general setting, namely bidirectional pipes that is as performant as pipes, conduit, and streamly, which are other common Haskell stream processing libraries.

Programs for Cheap!

- Computer Science2015 30th Annual ACM/IEEE Symposium on Logic in Computer Science
- 2015

The purpose of this paper is to explain these tricks to tell an optimization theorem that the operator satisfies, and give a proof of correctness for the optimisation, along with a formal guarantee about its effect on performance.

Deforestation

- The International Encyclopedia of Biological Anthropology
- 2018

Deforestation occurs in many ways. Most of the clearing is done for agricultural purposes—grazing cattle, planting crops. Poor farmers chop down a small area (typically a few acres) and burn the tree…

## References

SHOWING 1-10 OF 71 REFERENCES

Short cut fusion is correct

- Computer ScienceJ. Funct. Program.
- 2003

This paper shows that programs which have undergone short cut fusion are contextually equivalent to their unfused counterparts, and uses Pitts' recent demonstration that contextual equivalence in such languages is parametric to provide the first formal proof of the correctness ofShort cut fusion for them.

Warm fusion: deriving build-catas from recursive definitions

- Computer ScienceFPCA '95
- 1995

This paper shows how to transform recursive programs into this form automatically, thus enabling the fusion transformation to reapplied more easily than before, and challenges compiler writers to decide how many passes their compiler should perform.

Stream fusion: from lists to streams to nothing at all

- Computer ScienceICFP '07
- 2007

An automatic deforestation system, stream fusion, based on equational transformations, that fuses a wider range of functions than existing short-cut fusion systems, and reimplemented the Haskell standard List library on top of this framework, providing stream fusion for Haskell lists.

Functional array fusion

- Computer ScienceICFP '01
- 2001

A novel form of combinator loop fusion, which by removing intermediate structures optimizes the use of the memory hierarchy, is discussed, which naturally generalizes to a parallel implementation and includes facilities for optimizing load balancing and communication.

Cheap deforestation for non-strict functional languages

- Computer Science
- 1996

A new approach to deforestation is presented and one important conclusion is that a new analysis is required to infer function arities and the linearity of lambda abstractions that renders the basic deforestation algorithm far more effective.

Stream Fusion

- Computer ScienceArch. Formal Proofs
- 2009

These theories contain a formalization of much of the Stream Fusion library in HOLCF, and lazy list and stream types are defined, along with coercions between the two types, as well as an equivalence relation for streams that generate the same list.

Lightweight fusion by fixed point promotion

- Computer SciencePOPL '07
- 2007

This paper proposes a lightweight fusion method for general recursive function definitions that 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.

The Impact of seq on Free Theorems-Based Program Transformations

- Computer ScienceFundam. Informaticae
- 2006

This paper uses asymmetry introduced by left-closedness to derive criteria ensuring that both equational and inequational versions of short cut fusion and related program transformations based on free theorems hold in the presence of seq.

Chasing Bottoms: A Case Study in Program Verification in the Presence of Partial and Infinite Values

- Computer ScienceMPC
- 2004

This work describes a method for testing properties of programs in the presence of partial and infinite values and proves that the programs they have written are in fact (more or less) inverses using first fixpoint induction and then the approximation lemma.

Compact Fusion

- Computer ScienceMSFP@MPC
- 2006

This paper explores the problem for the case when the intermediate structure is a list, and formalises the space behaviour of the solution by means of program transformation techniques and the use of abstract machines.