Intermediate data structures are widely used in functional programs. Programs which use these intermediate structures are usually a lot easier to understand, but they result in loss of efficiency at run-time. In order to reduce these run-time costs, a transformation algorithm called deforestation was proposed by Wadler which could eliminate intermediate structures. However, this transformation algorithm was formulated only for first order functional programs. In this paper, it is shown how the original deforestation algorithm can be extended to deal with higher order functional programs. This extended algorithm is guaranteed to terminate only for expressions in which all functions are in a treeless form. It is shown how all function definitions can be generalised to this form so that the algorithm can be made to terminate for all programs. It is therefore argued that this algorithm is suitable for inclusion in an optimising compiler. i Contents 1 Introduction 1 2 Language 1 3 High...