Code reuse through polymorphic variants

Jacques Garrigue. In Workshop on Foundations of Software Engineering. Sasaguri, Japan, November 2000.

Abstract. Their support for code reuse has made object-oriented languages popular. However, they do not succeed equally in all areas, particularly when data has a complex structure, making hard to keep the parallel between data and code.

On the other hand, functional programming languages, which separate data from code, are better at handling complex structures, but they do not provide direct ways to reuse code for a different datatype.

We show here a way to achieve code reuse, even when data and code are separated. The method is illustrated by a detailed example.

You can get the A4 postscript version of this paper.


Here is the code for examples in the paper:

mixev.ml
The evaluator presented in the paper. Updated for ocaml 3.04. (original version)
mixev2.ml
Full source of the sum type version of the evaluator.
mixin2.ml
Larger example, using objects to structure code. Updated for ocaml 3.04.

JG 2002.01.11