page 1  (52 pages)
2to next section

The implementation of the Gofer functional programming system

Mark P. Jones

Yale University, Department of Computer Science,

P.O. Box 208285, New Haven, CT 06520-8285.

Research Report YALEU/DCS/RR-1030 May 1994


The Gofer system is a functional programming environment for a small, Haskell-like language. Supporting a wide range of different machines, including home computers, the system is widely used, both for teaching and research.

This report describes the main ideas and techniques used in the implementation of Gofer. This information will be particularly useful for work using Gofer as a platform to explore the use of new language features or primitives. It should also be of interest to those curious to see how the general techniques of functional programming language compilation are adapted to a simple, but practical, implementation.


The Gofer system is a functional programming environment for a small, Haskell-like language. The language can be characterized by its support for lazy evaluation and higher-order functions, and a static type system that includes both polymorphism and overloading. First released in September 1991, Gofer is widely used, both for education and research. Judging from comments from its users, there are two main reasons for Gofer's popularity. First, that it runs on a wide range of machines, including small home computers. Second, particularly on more powerful systems, the interpreter provides a fast, interactive development environment, avoiding the need for lengthy recompilation.

While the user documentation [24] and C source code for Gofer have always been included in public distributions, there was no substantial effort to provide details about the implementation. At the time, this seemed unnecessary; although it introduced some new ideas, most of the techniques used were believed to be standard and well-known.

In retrospect, user feedback during the past few years suggests that some of these ideas may not be as wellknown as we had expected. There has also been quite a lot of interest in modifying the Gofer system, from simple tasks such as the addition of new primitives, to more sophisticated experiments in language design. While this information can, in principle, be gleaned by a careful study of the source code, it is certainly not the most convenient form of documentation!

This report is intended as a guide for those interested in the inner workings of Gofer. Its aim is to explain the original design goals, the overall structure, the datatypes used, and the way that the different pieces fit together. It does not attempt to cover every technical detail of the system and should be viewed as an introduction, not a replacement, for studies of the source code. Nor is this report intended as a tutorial on `the implementation of functional languages'; indeed, Simon Peyton Jones' book by that name [48] was a constant companion during the development of Gofer, and remains an almost certain prerequisite to this report.

Throughout this report, we assume familiarity with the Gofer environment as described in the user documentation [24, 25, 32], with the Haskell functional programming language on which much of the language design is based [16], and with the C programming language in which the system is implemented.

Outline of report

We begin in Section 1, outlining the principal design goals for the development of the Gofer system. Section 2 summarizes the main features of the system from the user's perspective, highlighting some of the decisions made in the design of the standard user interface. In Section 3, we begin a more detailed study of the current implementation of Gofer. Starting with an overview of the whole system, we progress through