Stream fusion : practical shortcut fusion for coinductive sequence types

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 intermed...

Full description

Bibliographic Details
Main Author: Coutts, Duncan
Other Authors: de Moor, Oege
Published: University of Oxford 2011
Subjects:
Online Access:http://ethos.bl.uk/OrderDetails.do?uin=uk.bl.ethos.572593
id ndltd-bl.uk-oai-ethos.bl.uk-572593
record_format oai_dc
spelling ndltd-bl.uk-oai-ethos.bl.uk-5725932015-03-20T04:37:13ZStream fusion : practical shortcut fusion for coinductive sequence typesCoutts, Duncande Moor, Oege2011In 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 types that can be viewed as coinductive sequences. The fusion transformation can be applied fully automatically by a general purpose optimising compiler. The stream fusion technique itself has been presented previously and many practical implementations exist. The primary contributions of this thesis address the issues of correctness and optimisation: whether the transformation is correct and whether the transformation is an optimisation. Proofs of shortcut fusion laws have typically relied on parametricity by making use of free theorems. Unfortunately, most functional programming languages have semantics for which classical free theorems do not hold unconditionally; additional side conditions are required. In this thesis we take an approach based not on parametricity but on data abstraction. Using this approach we prove the correctness of stream fusion for lists -- encompassing the fusion system as a whole, not merely the central fusion law. We generalise this proof to give a framework for proving the correctness of stream fusion for any abstract data type that can be viewed as a coinductive sequence and give as an instance of the framework, a simple model of arrays. The framework requires that each fusible function satisfies a simple data abstraction property. We give proofs of this property for several standard list functions. Previous empirical work has demonstrated that stream fusion can be an optimisation in many cases. In this thesis we take a more universal view and consider the issue of optimisation independently of any particular implementation or compiler. We make a semi-formal argument that, subject to certain syntactic conditions on fusible functions, stream fusion on lists is strictly an improvement, as measured by the number of allocations of data constructors. This detailed analysis of how stream fusion works may be of use in writing fusible functions or in developing new implementations of stream fusion.005.114Computer science (mathematics) : Computing : Program development and tools : functional programming : program fusion : deforestation : program optimisation : program transformationUniversity of Oxfordhttp://ethos.bl.uk/OrderDetails.do?uin=uk.bl.ethos.572593http://ora.ox.ac.uk/objects/uuid:b4971f57-2b94-4fdf-a5c0-98d6935a44daElectronic Thesis or Dissertation
collection NDLTD
sources NDLTD
topic 005.114
Computer science (mathematics) : Computing : Program development and tools : functional programming : program fusion : deforestation : program optimisation : program transformation
spellingShingle 005.114
Computer science (mathematics) : Computing : Program development and tools : functional programming : program fusion : deforestation : program optimisation : program transformation
Coutts, Duncan
Stream fusion : practical shortcut fusion for coinductive sequence types
description 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 types that can be viewed as coinductive sequences. The fusion transformation can be applied fully automatically by a general purpose optimising compiler. The stream fusion technique itself has been presented previously and many practical implementations exist. The primary contributions of this thesis address the issues of correctness and optimisation: whether the transformation is correct and whether the transformation is an optimisation. Proofs of shortcut fusion laws have typically relied on parametricity by making use of free theorems. Unfortunately, most functional programming languages have semantics for which classical free theorems do not hold unconditionally; additional side conditions are required. In this thesis we take an approach based not on parametricity but on data abstraction. Using this approach we prove the correctness of stream fusion for lists -- encompassing the fusion system as a whole, not merely the central fusion law. We generalise this proof to give a framework for proving the correctness of stream fusion for any abstract data type that can be viewed as a coinductive sequence and give as an instance of the framework, a simple model of arrays. The framework requires that each fusible function satisfies a simple data abstraction property. We give proofs of this property for several standard list functions. Previous empirical work has demonstrated that stream fusion can be an optimisation in many cases. In this thesis we take a more universal view and consider the issue of optimisation independently of any particular implementation or compiler. We make a semi-formal argument that, subject to certain syntactic conditions on fusible functions, stream fusion on lists is strictly an improvement, as measured by the number of allocations of data constructors. This detailed analysis of how stream fusion works may be of use in writing fusible functions or in developing new implementations of stream fusion.
author2 de Moor, Oege
author_facet de Moor, Oege
Coutts, Duncan
author Coutts, Duncan
author_sort Coutts, Duncan
title Stream fusion : practical shortcut fusion for coinductive sequence types
title_short Stream fusion : practical shortcut fusion for coinductive sequence types
title_full Stream fusion : practical shortcut fusion for coinductive sequence types
title_fullStr Stream fusion : practical shortcut fusion for coinductive sequence types
title_full_unstemmed Stream fusion : practical shortcut fusion for coinductive sequence types
title_sort stream fusion : practical shortcut fusion for coinductive sequence types
publisher University of Oxford
publishDate 2011
url http://ethos.bl.uk/OrderDetails.do?uin=uk.bl.ethos.572593
work_keys_str_mv AT couttsduncan streamfusionpracticalshortcutfusionforcoinductivesequencetypes
_version_ 1716785803942690816