Results 1  10
of
20
Stream Fusion. From Lists to Streams to Nothing at All
 ICFP’07
, 2007
"... This paper presents an automatic deforestation system, stream fusion, based on equational transformations, that fuses a wider range of functions than existing shortcut fusion systems. In particular, stream fusion is able to fuse zips, left folds and functions over nested lists, including list compr ..."
Abstract

Cited by 43 (8 self)
 Add to MetaCart
This paper presents an automatic deforestation system, stream fusion, based on equational transformations, that fuses a wider range of functions than existing shortcut 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.
Free Theorems in the Presence of seq
, 2004
"... Parametric polymorphism constrains the behavior of pure functional programs in a way that allows the derivation of interesting theorems about them solely from their types, i.e., virtually for free. Unfortunately, the standard parametricity theorem fails for nonstrict languages supporting a polymorph ..."
Abstract

Cited by 36 (12 self)
 Add to MetaCart
Parametric polymorphism constrains the behavior of pure functional programs in a way that allows the derivation of interesting theorems about them solely from their types, i.e., virtually for free. Unfortunately, the standard parametricity theorem fails for nonstrict languages supporting a polymorphic strict evaluation primitive like Haskell's $\mathit{seq}$. Contrary to the folklore surrounding $\mathit{seq}$ and parametricity, we show that not even quantifying only over strict and bottomreflecting relations in the $\forall$clause of the underlying logical relation  and thus restricting the choice of functions with which such relations are instantiated to obtain free theorems to strict and total ones  is sufficient to recover from this failure. By addressing the subtle issues that arise when propagating up the type hierarchy restrictions imposed on a logical relation in order to accommodate the strictness primitive, we provide a parametricity theorem for the subset of Haskell corresponding to a GirardReynoldsstyle calculus with fixpoints, algebraic datatypes, and $\mathit{seq}$. A crucial ingredient of our approach is the use of an asymmetric logical relation, which leads to ``inequational'' versions of free theorems enriched by preconditions guaranteeing their validity in the described setting. Besides the potential to obtain corresponding preconditions for standard equational free theorems by combining some new inequational ones, the latter also have value in their own right, as is exemplified with a careful analysis of $\mathit{seq}$'s impact on familiar program transformations.
Concatenate, Reverse and Map Vanish For Free
, 2002
"... We introduce a new transformation method to eliminate intermediate data structures occurring in functional programs due to repeated list concatenations and other data manipulations (additionally exemplified with list reversal and mapping of functions over lists). The general idea is to uniformly abs ..."
Abstract

Cited by 25 (9 self)
 Add to MetaCart
We introduce a new transformation method to eliminate intermediate data structures occurring in functional programs due to repeated list concatenations and other data manipulations (additionally exemplified with list reversal and mapping of functions over lists). The general idea is to uniformly abstract from data constructors and manipulating operations by means of rank2 polymorphic combinators that exploit algebraic properties of these operations to provide an optimized implementation. The correctness of transformations is proved by using the free theorems derivable from parametric polymorphic types.
Monadic augment and generalised short cut fusion
 Journal of Functional Programming
, 2005
"... Monads are commonplace programming devices that are used to uniformly structure computations with effects such as state, exceptions, and I/O. This paper further develops the monadic programming paradigm by investigating the extent to which monadic computations can be optimised by using generalisatio ..."
Abstract

Cited by 15 (7 self)
 Add to MetaCart
Monads are commonplace programming devices that are used to uniformly structure computations with effects such as state, exceptions, and I/O. This paper further develops the monadic programming paradigm by investigating the extent to which monadic computations can be optimised by using generalisations of short cut fusion to eliminate monadic structures whose sole purpose is to “glue together ” monadic program components. We make several contributions. First, we show that every inductive type has an associated build combinator and an associated short cut fusion rule. Second, we introduce the notion of an inductive monad to describe those monads that give rise to inductive types, and we give examples of such monads which are widely used in functional programming. Third, we generalise the standard augment combinators and cata/augment fusion rules for algebraic data types to types induced by inductive monads. This allows us to give the first cata/augment rules for some common data types, such as rose trees. Fourth, we demonstrate the practical applicability of our generalisations by providing Haskell implementations for all concepts and examples in the paper. Finally, we offer deep theoretical insights by showing that the augment combinators are monadic in nature, and thus that our cata/build and cata/augment rules are arguably the best generally applicable fusion rules obtainable.
Rewriting Haskell Strings
 In Practical Aspects of Declarative Languages 8th International Symposium, PADL 2007
, 2007
"... Abstract The Haskell String type is notoriously inefficient. We introduce a new data type, ByteString, based on lazy lists of byte arrays, combining the speed benefits of strict arrays with lazy evaluation. Equational transformations based on term rewriting are used to deforest intermediate ByteStri ..."
Abstract

Cited by 14 (6 self)
 Add to MetaCart
Abstract The Haskell String type is notoriously inefficient. We introduce a new data type, ByteString, based on lazy lists of byte arrays, combining the speed benefits of strict arrays with lazy evaluation. Equational transformations based on term rewriting are used to deforest intermediate ByteStrings automatically. We describe novel fusion combinators with improved expressiveness and performance over previous functional array fusion strategies. A library for ByteStrings is implemented, providing a purely functional interface, which approaches the speed of lowlevel mutable arrays in C.
An Accumulative Parallel Skeleton for All
, 2001
"... Parallel skeletons intend to encourage programmers to build... ..."
Abstract

Cited by 13 (10 self)
 Add to MetaCart
Parallel skeletons intend to encourage programmers to build...
The Impact of seq on Free TheoremsBased Program Transformations
 Fundamenta Informaticae
, 2006
"... Parametric polymorphism constrains the behavior of pure functional programs in a way that allows the derivation of interesting theorems about them solely from their types, i.e., virtually for free. Unfortunately, standard parametricity results — including socalled free theorems — fail for nonstrict ..."
Abstract

Cited by 13 (5 self)
 Add to MetaCart
Parametric polymorphism constrains the behavior of pure functional programs in a way that allows the derivation of interesting theorems about them solely from their types, i.e., virtually for free. Unfortunately, standard parametricity results — including socalled free theorems — fail for nonstrict languages supporting a polymorphic strict evaluation primitive such as Haskell’s seq. A folk theorem maintains that such results hold for a subset of Haskell corresponding to a GirardReynolds calculus with fixpoints and algebraic datatypes even when seq is present provided the relations which appear in their derivations are required to be bottomreflecting and admissible. In this paper we show that this folklore is incorrect, but that parametricity results can be recovered in the presence of seq by restricting attention to leftclosed, total, and admissible relations instead. The key novelty of our approach is the asymmetry introduced by leftclosedness, which leads to “inequational” versions of standard parametricity results together with preconditions guaranteeing their validity even when seq is present. We use these results 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.
Typeinference based short cut deforestation (nearly) without inlining
 In IFL'99, Lochem, The Netherlands, Proceedings
, 1999
"... Deforestation optimises a functional program by transforming it into another one that does not create certain intermediate data structures. In [Chi99] we presented a typeinference based deforestation algorithm which performs extensive inlining. However, across module boundaries only limited inlinin ..."
Abstract

Cited by 5 (1 self)
 Add to MetaCart
Deforestation optimises a functional program by transforming it into another one that does not create certain intermediate data structures. In [Chi99] we presented a typeinference based deforestation algorithm which performs extensive inlining. However, across module boundaries only limited inlining is practically feasible. Furthermore, inlining is a nontrivial transformation which is therefore best implemented as a separate optimisation pass. To perform short cut deforestation (nearly) without inlining, Gill suggested to split definitions into workers and wrappers and inline only the small wrappers, which transfer the information needed for deforestation. We show that Gill’s use of a function build limits deforestation and note that his reasons for using build do not apply to our approach. Hence we develop a more general worker/wrapper scheme without build. We give a typeinference based algorithm which splits definitions into workers and wrappers. Finally, we show that we can deforest more expressions with the worker/wrapper scheme than the algorithm with inlining. 1 TypeInferenceBased Short Cut Deforestation In lazy functional programs two functions are often glued together by an intermediate data structure that is produced by one function and consumed by the other. For example, the function any, which tests whether any element of a list xs satisfies a given predicate p, may be defined as follows in Haskell [PH + 99]: any p xs = or (map p xs) The function map applies p to all elements of xs yielding a list of boolean values. The function or combines these boolean values with the logical or operation (). Although lazy evaluation makes this modular programming style practicable [Hug89], it does not come for free. Each list cell has to be allocated, filled, taken apart and finally garbage collected. The following monolithic definition of any is more efficient. any p [] = False any p (x:xs) = p x   any p xs It is the aim of deforestation algorithms to automatically transform a functional program into another one that does not create such intermediate data structures. We say that the producer and the consumer of the data structure are fused.
On Deforesting Parameters of Accumulating Maps
 In Logic Based Program Synthesis and Transformation, 11th International Workshop, LOPSTR 2001, volume 2372 of LNCS
, 2002
"... Deforestation is a wellknown program transformation technique which eliminates intermediate data structures that are passed between functions. One of its weaknesses is the inability to deforest programs using accumulating parameters. ..."
Abstract

Cited by 5 (0 self)
 Add to MetaCart
Deforestation is a wellknown program transformation technique which eliminates intermediate data structures that are passed between functions. One of its weaknesses is the inability to deforest programs using accumulating parameters.
A family of syntactic logical relations for the semantics of Haskelllike languages
 INFORMATION AND COMPUTATION
, 2009
"... Logical relations are a fundamental and powerful tool for reasoning about programs in languages with parametric polymorphism. Logical relations suitable for reasoning about observational behavior in polymorphic calculi supporting various programming language features have been introduced in recent y ..."
Abstract

Cited by 5 (3 self)
 Add to MetaCart
Logical relations are a fundamental and powerful tool for reasoning about programs in languages with parametric polymorphism. Logical relations suitable for reasoning about observational behavior in polymorphic calculi supporting various programming language features have been introduced in recent years. Unfortunately, the calculi studied are typically idealized, and the results obtained for them offer only partial insight into the impact of such features on observational behavior in implemented languages. In this paper we show how to bring reasoning via logical relations closer to bear on real languages by deriving results that are more pertinent to an intermediate language for the (mostly) lazy functional language Haskell like GHC Core. To provide a more finegrained analysis of program behavior than is possible by reasoning about program equivalence alone, we work with an abstract notion of relating observational behavior of computations which has among its specializations both observational equivalence and observational approximation. We take selective strictness into account, and we consider the impact of different kinds of