## Monadic augment and generalised short cut fusion (2005)

### Cached

### Download Links

- [crab.rutgers.edu]
- [crab.rutgers.edu]
- [personal.cis.strath.ac.uk]
- [www.cs.ioc.ee]
- DBLP

### Other Repositories/Bibliography

Venue: | Journal of Functional Programming |

Citations: | 15 - 7 self |

### BibTeX

@INPROCEEDINGS{Ghani05monadicaugment,

author = {Neil Ghani and Patricia Johann},

title = {Monadic augment and generalised short cut fusion},

booktitle = {Journal of Functional Programming},

year = {2005},

pages = {294--305},

publisher = {ACM Press}

}

### OpenURL

### Abstract

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.

### Citations

1335 | The essence of functional programming
- Wadler
- 1992
(Show Context)
Citation Context ...ived by Moggi, monads form a useful computational abstraction which models diverse effects such as stateful computations, exceptions, and I/O in a modular, uniform, and principled manner [13]. Wadler =-=[24]-=- led the call to turn Moggi’s theory of effectful computation into a practical programming methodology, and showed how to use monads to structure such computations. Monads are now firmly established a... |

745 | Notions of computation and monads
- Moggi
- 1991
(Show Context)
Citation Context ...ginally conceived by Moggi, monads form a useful computational abstraction which models diverse effects such as stateful computations, exceptions, and I/O in a modular, uniform, and principled manner =-=[13]-=-. Wadler [24] led the call to turn Moggi’s theory of effectful computation into a practical programming methodology, and showed how to use monads to structure such computations. Monads are now firmly ... |

199 | A short cut to deforestation
- Gill, Launchbury, et al.
- 1993
(Show Context)
Citation Context ...e technique which has been used to improve modularly constructed functional programs, and a number of fusion transformations appropriate to the non-monadic setting have been developed in recent years =-=[1, 6, 7, 8, 9, 19, 20, 21, 23]-=-. Perhaps the best known of these is short cut fusion [6], a local transformation based upon two combinators — build, which produces lists in a uniform manner, and foldr, which uniformly consumes them... |

111 | A fold for all seasons
- Sheard, Fegaras
- 1993
(Show Context)
Citation Context ...e technique which has been used to improve modularly constructed functional programs, and a number of fusion transformations appropriate to the non-monadic setting have been developed in recent years =-=[1, 6, 7, 8, 9, 19, 20, 21, 23]-=-. Perhaps the best known of these is short cut fusion [6], a local transformation based upon two combinators — build, which produces lists in a uniform manner, and foldr, which uniformly consumes them... |

96 | Bananas in space: extending fold and unfold to exponential types
- Meijer, Hutton
- 1995
(Show Context)
Citation Context ...ributes to the fruitful line of research into generic recursion combinators. Research in this area has led, for example, to the generalisation of fold for lists to arbitrary mixed variance data types =-=[2, 11]-=-. • Like us, Pardo [14] sought to understand fusion in the context of monadic computation, but his goal was different from ours. Pardo investigated conditions under which an expression of type M(µF ),... |

92 | Shortcut to Deforestation in Calculational Form
- Takano, Meijer
- 1995
(Show Context)
Citation Context ...e technique which has been used to improve modularly constructed functional programs, and a number of fusion transformations appropriate to the non-monadic setting have been developed in recent years =-=[1, 6, 7, 8, 9, 19, 20, 21, 23]-=-. Perhaps the best known of these is short cut fusion [6], a local transformation based upon two combinators — build, which produces lists in a uniform manner, and foldr, which uniformly consumes them... |

84 | Algebraic data types and program transformation - Malcolm - 1990 |

75 | Parametric polymorphism and operational equivalence
- Pitts
(Show Context)
Citation Context ...f constructing parametric models which respect the categorical semantics given there. An alternative approach to correctness is taken in [8], where the operational semantics-based parametric model of =-=[17]-=- is used to validate the fusion rules for algebraic data types introduced in that paper. Extending these techniques to tie the correctness of our monadic fusion rules into an operational semantics of ... |

65 | Cheap deforestation for non-strict functional languages
- Gill
- 1996
(Show Context)
Citation Context ...press in a manner suitable for short cut fusion. This led Gill to introduce a list producer, called augment, which generalises build, together with an accompanying foldr/augment fusion rule for lists =-=[5]-=-. This rule has 1 Monads, such as the expression monad in Example 1, which correspond to ordinary algebraic data types can be thought of as having an effect of storing data in a data structure.ssubseq... |

55 | Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space
- Fegaras, Sheard
- 1996
(Show Context)
Citation Context ...ributes to the fruitful line of research into generic recursion combinators. Research in this area has led, for example, to the generalisation of fold for lists to arbitrary mixed variance data types =-=[2, 11]-=-. • Like us, Pardo [14] sought to understand fusion in the context of monadic computation, but his goal was different from ours. Pardo investigated conditions under which an expression of type M(µF ),... |

55 | Notions of computation determine monads
- Plotkin, Power
- 2002
(Show Context)
Citation Context ...ata type. EXAMPLE 5. The algebraic data type Expr a in Example 1 is M (E a) for the functor E a defined by data E a b = Var a | Lit Int | Op Ops b b EXAMPLE 6. An interactive input/output computation =-=[18]-=- is either i) a value of type a, ii) an input action, which for every input token of type i results in a new interactive input/output computation, or iii) an output of an output token of type o and a ... |

50 | Merging monads and folds for functional programming
- Meijer, Jeuring
- 1995
(Show Context)
Citation Context ...onad M an ambient structure which was not to be eliminated by the fusion rule. Our goal, on the other hand, is to eliminate the construction of precisely such monadic structures. • In a similar vein, =-=[12]-=- develops a variety of fusion laws in the monadic setting, including a short cut deforestation law for eliminating intermediate structures of the form M(List X). However, as with [14], the aim is not ... |

47 | Deriving structural hylomorphisms from recursive definitions
- Hu, Iwasaki, et al.
- 1996
(Show Context)
Citation Context |

43 | Shortcut fusion for accumulating parameters & zip-like functions
- Svenningsson
- 2002
(Show Context)
Citation Context |

26 | Type inference builds a short cut to deforestation
- Chitil
- 1999
(Show Context)
Citation Context |

25 | Concatenate, reverse and map vanish for free
- Voigtländer
- 2002
(Show Context)
Citation Context |

17 |
A generalization of short-cut fusion and its correctness proof
- Johann
(Show Context)
Citation Context |

14 | Fusion of Recursive Programs with Computational Effects
- Pardo
(Show Context)
Citation Context ...ne of research into generic recursion combinators. Research in this area has led, for example, to the generalisation of fold for lists to arbitrary mixed variance data types [2, 11]. • Like us, Pardo =-=[14]-=- sought to understand fusion in the context of monadic computation, but his goal was different from ours. Pardo investigated conditions under which an expression of type M(µF ), for M a monad and F a ... |

5 | Categorical semantics and composition of tree transducers - Jürgensen - 2003 |

4 | V.: Build, augment and destroy. universally
- Ghani, Uustalu, et al.
(Show Context)
Citation Context ...as input a function g providing a type-independent template for constructing “abstract” lists, and produces a corresponding “concrete” list. For example, build (\c n -> c 3 (c 7 n)) produces the list =-=[3,7]-=-. The Haskell definitions of foldr and build, as well as those of other list-processing functions used in this paper, are given in Figure 1. The recursive combinator foldr is standard in the Haskell p... |

4 | Generalizing substitution
- Uustalu
- 2003
(Show Context)
Citation Context ... inductive monads do. To describe these monads, we introduce the notion of a parameterised monad, and use the observation that the least fixed point of every parameterised monad is an inductive monad =-=[22]-=- to define generic augment combinators and cata/augment rules for all such fixed points. We illustrate our results with expression languages, rose trees, interactive input/output monads, and hyperfunc... |

3 |
V.: Generalizing the augment combinator
- Ghani, Uustalu, et al.
- 2006
(Show Context)
Citation Context ... category theory is assumed or required and, in order to make this paper accessible to as wide an audience as possible, the correctness of the fusion rules presented here is given in a separate paper =-=[4]-=-. On the other hand, this paper is addressed to the functional programming community and, aside from using the same combinators, is disjoint from [4]. 2. Why monads? Functional programming was recogni... |

2 |
98 Language and Libraries: The Revised Report
- L
- 2003
(Show Context)
Citation Context ...urn Moggi’s theory of effectful computation into a practical programming methodology, and showed how to use monads to structure such computations. Monads are now firmly established as part of Haskell =-=[16]-=-, supported by specific language features and used in a wide range of applications. The essential idea behind monads is the type-safe separation of values from effectful computations that return those... |

1 |
Using monads to fuse recursive programs (extended abstract). citeseer.ist.psu.edu/543861.html
- Juergensen
(Show Context)
Citation Context ...rt cut deforestation law for eliminating intermediate structures of the form M(List X). However, as with [14], the aim is not to eliminate the monad, but rather the list inside the monad. • Jürgensen =-=[9]-=- defined a fusion combinator based on the uniqueness of the map from a free monad to any other monad. Thus, his technique is really a different form of fusion from ours and, in particular, isn’t based... |

1 |
Zip fusion with hyperfunctions. citeseer.ist.psu.edu/launchbury00zip.html
- Launchbury, Krstic, et al.
(Show Context)
Citation Context ...[] is the list functor and instance FunctorPlus [] where zero = [] plus = (++) Our final example of a general mechanism for generating parameterised monads concerns a generalisation of hyperfunctions =-=[10]-=-. Here, we start with a contravariant “structure functor”, i.e., with a functor in the class class ContraFunctor f where cfmap :: (a -> b) -> f b -> f a EXAMPLE 14. If h is a contravariant functor, th... |

1 |
Playing by the rules: Rewriting as an optimization technique
- Jones, Tolmach, et al.
- 2001
(Show Context)
Citation Context ...augment-f :: (forall b. (a -> [b] -> b) -> b) -> (a -> Rose c) -> Rose c augment-f g k = g (\x t -> let Node y s = k x in Node y (t ++ s)) The definitions of cata-f and build-f coincide with those in =-=[15]-=-. Using the above definitions, we can also instantiate the generic derivation of the monad operations for Rose a from the operations for the underlying parameterised monad f. This gives return x = Nod... |

1 | Zip fusion with hyperfunctions. Available at www.cse.ogi.edu/∼krstic - Launchbury, Krstic, et al. - 2000 |