## The Concatenate Vanishes (1987)

Citations: | 15 - 0 self |

### BibTeX

@TECHREPORT{Wadler87theconcatenate,

author = {Philip Wadler},

title = {The Concatenate Vanishes},

institution = {},

year = {1987}

}

### OpenURL

### Abstract

This note presents a trivial transformation that can eliminate many calls of the concatenate (or “append”) operator from a program. The general form of the transformation is well known, and one of the examples, transforming the reverse function, is a classic. However, so far as I am aware, this style of transformation has not previously been systematised in the way done here. The transformation is suitable for incorporation in a compiler, and improves the asymptotic time complexity of some programs from quadratic to linear. There is a syntactic test that determines when the transformation will succeed in eliminating a concatenate operation. Section 1 describes the transformation. Section 2 presents examples. Section 3 characterises the transformation’s benefits. Section 4 describes related work. Section 5 concludes. 1 The transformation First, some notational preliminaries. We write concatenate as infix +, list construction (cons) as infix:, and the empty list as []. We write [x, y, z] as an abbreviation for x: (y: (z: [])). We will make use of the following laws: (1) [ ] + x = x (2) (x: y) + z = x: (y + z) (3) (x + y) + z = x + (y + z) Laws (1) and (2) provide a recursive definition of concatenate. Law (3) states that concatenate is associative; it may be proved from laws (1) and (2). We now describe the transformation. The key idea is that whenever an application of a function f may appear as the left argument of a concatenation, then we introduce a new function f ′ , satisfying the property

### Citations

590 | A transformation system for developing recursive programs
- Burstall, Darlington
- 1977
(Show Context)
Citation Context ... applied is immaterial. When no more rewrites can be applied, the transformation is complete. The validity of this transformation is easy to verify, as it fits directly into Burstall and Darlington's =-=[BD77]-=- classic program transformation approach. 2 Examples 2.1 Reverse A function to reverse a list is defined by the script reverse [ ] = [ ] reverse (x : xs) = reverse xs ++ [x ] To apply the transformati... |

419 | Deforestation: Transforming Programs to Eliminate Trees
- Wadler
- 1988
(Show Context)
Citation Context ...dded to a compiler, and a precise characterisation of the effect on efficiency has been given. It may be possible to combine the transformation described here with the "deforestation " trans=-=formation [Wad88]-=-. Doing so may eliminate some of the shortcomings described in Sections 2.4 and 2.5. 5 Conclusions A simple algorithm has been presented that removes many instances of concatenate from a program. The ... |

152 |
Miranda: a non-strict functional language with polymorphic types
- Turner
- 1985
(Show Context)
Citation Context ...rwell [WMR87] interpreter show that the transformed definition requires about 10% less in run time, number of reductions performed, and number of cells allocated. Measurements made with the Miranda 1 =-=[Tur85]-=- interpreter show a similar improvement. 2.4 Flattening a list of lists Here are some examples of scripts not improved by the transformation. A function to concatenate a list of lists is defined by th... |

48 |
A novel representation of lists and its application to the function “reverse
- Hughes
- 1986
(Show Context)
Citation Context ...equiring constant asymptotic time, while the model in Section 3 now describes when run-time overhead will be eliminated. The transformation given here has much the same effect as the one described in =-=[Hug86]-=-. The main difference is that the transformation here is described in such a way that it could be added to a compiler, and a precise characterisation of the effect on efficiency has been given. It may... |

10 |
A short note concerning lazy reduction rules for append. Softw: Pract
- Sleep, Holmström
- 1982
(Show Context)
Citation Context ...del, we can predict that reverse and traverse, as given above, will improve from quadratic to linear, whereas qsort will retain the same asymptotic time complexity. 4 Related work Sleep and Holmstrom =-=[SH82]-=- have described an ingenious implementation of concatenate. Their run-time implementation is more flexible than the compile-time transformation described here, but it incurs higher overhead. For examp... |

2 |
An introduction to Orwell. Programming Research
- Wadler, Miller, et al.
- 1987
(Show Context)
Citation Context ...worst case, and n log n in the average case, where n is the length of the input list. However, the transformed definition has a slightly better absolute performance. Measurements made with the Orwell =-=[WMR87]-=- interpreter show that the transformed definition requires about 10% less in run time, number of reductions performed, and number of cells allocated. Measurements made with the Miranda 1 [Tur85] inter... |