Type classes an exploration of the design space
Simon Peyton Jones Mark Jones
University of Glasgow and Oregon Graduate Institute University of Nottingham
Erik Meijer
University of Utrecht and Oregon Graduate Institute
May
Abstract to Haskell can b e a painful exp erience One feature that is
particularly often missed is multi parameter type classes
Section explains why
When type classes were rst introduced in Haskell they
were regarded as a fairly exp erimental language feature and
The obvious question is whether there is an upward
therefore warranted a fairly conservative design Since that
compatible way to extend Haskell s class system to enjoy
time practical exp erience has convinced many programmers
some or all of the expressiveness that Gofer provides and
of the b ene ts and convenience of type classes However on
p erhaps some more b esides The main b o dy of this pap er
o ccasion these same programmers have discovered examples
explores this question in detail It turns out that there are
where seemingly natural applicatio ns for type class overload
a number of interlocking design decisions to b e made Gofer
ing are prevented by the restrictions imp osed by the Haskell
and Haskell each embo dy a particular set but it is very
design
useful to tease them out indep endently and see how they
interact Our goal is to explore the design space as clearly
It is p ossible to extend the type class mechanism of Haskell
as p ossible laying out the choices that must b e made and
in various ways to overcome these limitations but such pro
the factors that a ect them rather than prescribing a par
p osals must b e designed with great care For example sev
ticular solution Section We nd that the design space
eral di erent extensions have b een implemented in Gofer
is rather large we identify nine separate design decisions
Some of these particularly the supp ort for multi parameter
each of which has two or more p ossible choices though not
classes have proved to b e very useful but interactions b e
all combinations of choices make sense In the end however
tween other asp ects of the design have resulted in a type
we do o er our own opinion ab out a sensible set of choices
system that is b oth unsound and undecidable Another illus