## Generic Program Transformation (1998)

### Cached

### Download Links

- [www.comlab.ox.ac.uk]
- [web.comlab.ox.ac.uk]
- DBLP

### Other Repositories/Bibliography

Venue: | Proc. 3rd International Summer School on Advanced Functional Programming, LNCS 1608 |

Citations: | 30 - 5 self |

### BibTeX

@INPROCEEDINGS{Moor98genericprogram,

author = {Oege De Moor and Ganesh Sittampalam},

title = {Generic Program Transformation},

booktitle = {Proc. 3rd International Summer School on Advanced Functional Programming, LNCS 1608},

year = {1998},

pages = {116--149},

publisher = {Springer-Verlag}

}

### OpenURL

### Abstract

ion versus efficiency For concreteness, let us first examine a number of examples of the type of optimisation that we wish to capture, and the kind of programs on which they operate. This will give us a specific aim when developing the machinery for automating the process, and a yardstick for evaluating our results. 2.1 Minimum depth of a tree Consider the data type of leaf labelled binary trees: dataBtreea = Leaf a j Bin (Btree a)(Btree a) The minimum depth of such a tree is returned by the function mindepth :: Btree a ! Int : mindepth (Leaf a) = 0 mindepth (Bin s t) = min (mindepth s)(mindepth t) + 1 This program is clear, but rather inefficient. It traverses the whole tree, regardless of leaves that may occur at a small depth. A better program would keep track of the `minimum depth so far', and never explore subtrees beyond that current best solution. One possible implementation of that idea is mindepth t = md t 01 md (Leaf a)d m = mindm md (Bin s t)d m = if d 0 m then m...

### Citations

1309 | Monads for Functional Programming
- Wadler
- 1995
(Show Context)
Citation Context ...y to modify. Finally, we took inspiration from an unpublished term rewriting system by Mike Spivey. An elegant exposition of Spivey's program, with a number of important improvements, can be found in =-=[5]-=-. Bird also shows how Spivey's program can be used as a tool in program verification. A much more advanced tool for transforming Haskell programs is the HYLO system [16]. Other systems that perform th... |

936 | A theory of type polymorphism in progra.mming
- Milner
- 1978
(Show Context)
Citation Context ...ding material: a good introduction to the concepts used here can be found in [18]. 5.1 Types Expressions are typed in the Hindley-Milner discipline, without any modern extensions such as type classes =-=[15]-=-. More precisely, we shall be working with type schemes, as defined by the declaration dataType = Tid Tname j TconCname [Type] derivingEq That is, a type scheme is a variable (a type identifier), or a... |

570 | A Transformation System for Developing Recursive Programs
- Burstall, Darlington
- 1976
(Show Context)
Citation Context .... It does seem rather restrictive, however, for it does not allow for the application of rules in reverse direction. In particular, program development by means of the well known unfold/fold strategy =-=[7]-=- is not applicable: we can use a function definition in its evaluating direction, but never backwards, matching the right hand side and producing an instance of the left hand side. Instead, all induct... |

147 |
Proving and applying program transformations expressed with second-order patterns
- Huet, Lang
- 1978
(Show Context)
Citation Context ...n definitions is said to be a higher order matching algorithm. The observation that higher order matching should be a key ingredient of any program transformation tool was first made by Huet and Lang =-=[13]-=-. While fusion is elegant and amenable to mechanisation, it may appear that it only applies to programs that were written in terms of foldr to start with. What if we wish to improve a program that use... |

105 |
The implementation of functional programming languages
- PEYTON-JONES
- 1987
(Show Context)
Citation Context ...lgorithm that is implemented in MAG. This section admittedly requires a little bit more background knowledge than the preceding material: a good introduction to the concepts used here can be found in =-=[18]-=-. 5.1 Types Expressions are typed in the Hindley-Milner discipline, without any modern extensions such as type classes [15]. More precisely, we shall be working with type schemes, as defined by the de... |

82 | A transformation-based optimiser for Haskell
- Jones, Santos
- 1998
(Show Context)
Citation Context ...e e 2 ) = if c then f e 1 else f e 2 Of course these rules are not particular to the problem in hand. In fact, they are themselves instances of more general transformations involving case expressions =-=[19]-=-. Exercises 2.1 Can the computation of the maximum depth of a tree be made more efficient in the same way as the computation of the minimum depth? If not, which property of min fails for max? 2.2 A le... |

73 | Warm fusion: Deriving buildcatas from recursive definitions
- Launchbury, Sheard
- 1995
(Show Context)
Citation Context ...ol in program verification. A much more advanced tool for transforming Haskell programs is the HYLO system [16]. Other systems that perform the type of transformation considered here are described in =-=[2, 14]-=-. 4.1 Getting acquainted MAG takes two kinds of input file: programs and theories. A program is just a program in a functional programming language that is a small subset of Haskell. A theory is a set... |

67 |
Tabulation techniques for recursive programs
- Bird
- 1980
(Show Context)
Citation Context ...in a sense the dual of accumulation parameters: in the first case, we generalise the range of a function, and in the second case the domain. There is quite a large body of literature on tupling, e.g. =-=[3, 6, 8, 12, 17]-=-. In the exercises below, you will have the opportunity to explore its versatility: many programs can be improved through tupling. One could even say that the attribute grammar system presented by Swi... |

57 | Deterministic, error-correcting combinator parsers
- SWIERSTRA, DUPONCHEEL
- 1996
(Show Context)
Citation Context ... hastily written for these lectures. It is also an experiment in the use of the pretty printing, parsing and attribute grammar libraries provided by Swierstra and his colleagues at Utrecht University =-=[20]-=-: by using their libraries, we aimed to produce a system that is truly light weight and easy to modify. Finally, we took inspiration from an unpublished term rewriting system by Mike Spivey. An elegan... |

48 | The under-appreciated unfold
- Gibbons, Jones
- 1998
(Show Context)
Citation Context ... know what has to be done: all the definitions can be found in the theory file levels.eq. Produce an efficient program with MAG. This program and its derivation were first discovered and presented by =-=[10]-=-, and Jeremy Gibbons suggested it as an exercise in the use of MAG. His paper also presents another, arguably more elegant, method of computing the breadth first traversal. Minimum depth Let us now re... |

33 | Tupling calculation eliminates multiple data traversals
- Hu, Iwasaki, et al.
- 1997
(Show Context)
Citation Context ...in a sense the dual of accumulation parameters: in the first case, we generalise the range of a function, and in the second case the domain. There is quite a large body of literature on tupling, e.g. =-=[3, 6, 8, 12, 17]-=-. In the exercises below, you will have the opportunity to explore its versatility: many programs can be improved through tupling. One could even say that the attribute grammar system presented by Swi... |

33 | A Calculational Fusion System HYLO
- Onoue, Hu, et al.
- 1997
(Show Context)
Citation Context ...t improvements, can be found in [5]. Bird also shows how Spivey's program can be used as a tool in program verification. A much more advanced tool for transforming Haskell programs is the HYLO system =-=[16]-=-. Other systems that perform the type of transformation considered here are described in [2, 14]. 4.1 Getting acquainted MAG takes two kinds of input file: programs and theories. A program is just a p... |

18 | Efficient second-order matching
- Curien, Qian, et al.
- 1996
(Show Context)
Citation Context ...cts pattern variables to be of base type (such as Int , Bool or [Int ]), or functions between base types. For example, the KORSO transformation system, developed at Bremen, uses second-order matching =-=[9]-=-. Unfortunately the restriction to second-order variables is not a natural one when transforming Haskell programs. Consider, for example, our synthesis of a fast program for reverse: this would be bey... |

16 | Calculating accumulations
- Hu, Iwasaki, et al.
- 1999
(Show Context)
Citation Context ...nition is generalised by introducing an extra parameter. The parameter is used to accumulate additional information during a computation --- hence the name. The technique was studied in [4]; see also =-=[11]-=-. Fast reverse A naive definition of the function reverse is reverse [ ] = [ ] reverse (a : x ) = reverse x ++ [a] Write down the recursive definition of (++), and estimate how much time it takes to e... |

12 |
Improving recursive functions by inverting the order of evaluation
- Boiten
- 1992
(Show Context)
Citation Context ...in a sense the dual of accumulation parameters: in the first case, we generalise the range of a function, and in the second case the domain. There is quite a large body of literature on tupling, e.g. =-=[3, 6, 8, 12, 17]-=-. In the exercises below, you will have the opportunity to explore its versatility: many programs can be improved through tupling. One could even say that the attribute grammar system presented by Swi... |

9 |
Methodologies for Transformations and Memoing in Applicative Languages
- Pettorossi
- 1984
(Show Context)
Citation Context |

6 | A transformation system combining partial evaluation with term rewriting
- Bellegarde
- 1993
(Show Context)
Citation Context ...ol in program verification. A much more advanced tool for transforming Haskell programs is the HYLO system [16]. Other systems that perform the type of transformation considered here are described in =-=[2, 14]-=-. 4.1 Getting acquainted MAG takes two kinds of input file: programs and theories. A program is just a program in a functional programming language that is a small subset of Haskell. A theory is a set... |

5 |
The promotion and accumulation strategies in functional programming
- Bird
- 1984
(Show Context)
Citation Context ...efficient definition is generalised by introducing an extra parameter. The parameter is used to accumulate additional information during a computation --- hence the name. The technique was studied in =-=[4]-=-; see also [11]. Fast reverse A naive definition of the function reverse is reverse [ ] = [ ] reverse (a : x ) = reverse x ++ [a] Write down the recursive definition of (++), and estimate how much tim... |

5 |
Fusion and tupling transformations: Synergies and conflits
- Chin
- 1995
(Show Context)
Citation Context |

3 |
Functional pearl: On generating unique names
- Augustsson, Rittri, et al.
- 1994
(Show Context)
Citation Context ...d to an argument. Expansion is a bit trickier to code in Haskell than contraction, however, because of the need to generate fresh identifiers --- a notorious difficulty in a purely functional setting =-=[1]-=-. Equality. We define two expressions to be equal if one can be obtained from the other through repeated application of ff- and j-conversion. That test could be coded in Haskell as follows: instanceEq... |