Refactoring Functional Programs

Simon Thompson (University of Kent)

Refactoring is about improving the design of existing computer programs and systems; as such it is familiar to every programmer, software engineer and designer. Its key characteristic is the focus on structural change, strictly separated from changes in functionality. A structural change can make a program simpler, by removing duplicate code, say, or can be the preparatory step for an upgrade or extension of a system.

It is characteristic of refactorings that they are 'diffuse' and 'bureaucratic': consider the example of the simplest possible refactoring: renaming a component of a program. To effect this change requires not only the component definition to be changed, but also every use of the component must be similiarly modified. This involves changing every file/module which might use the component, potentially tens or hundreds of modules. Moreover, it is equally vital not to change any components hidden in other parts of the system which happen to share the same name. Of course, it is possible to do refactorings 'by hand', but this process is tedious and, more importantly, error-prone. Automated support for refactorings makes them safe and easy to perform and also secure in their implementation.

The 'Refactoring Functional Programs' project comprising Huiqing Li, Claus Reinke and Simon Thompson is building the HaRe system to support refactorings for Haskell programs. HaRe is designed as a serious tool for use by practising programmers: HaRe supports the whole of the Haskell; it is integrated into standard development environments and it preserves the 'look and feel' of refactored programs. HaRe is built using a number of existing libraries: 'Programatica' provides tools on which to build the language-analysis components, and 'Strafunski' gives general support for tree transformations.

The course at the Summer School will cover

  1. The basics of refactoring
  2. Haskell refactorings and the semantics of Haskell
  3. HaRe and its implementation
  4. Using HaRe for refactoring Haskell programs
  5. Writing your own refactorings

Last update 12 April 2004