It seems to be the season for records -- three proposals already and
I'm going to add a fourth one!  Phil Wadler, Martin Wehr and I have
recently completed a paper that describes a radical simplification of
type classes. We restrict overloading to functions that have the
instance type as first argument. We also do away with class
declarations altogether, and keep only a simple form of instance
declaration. 

This is described in the technical report "A second look at
overloading", to be found in the papers section of my WWW home page at
http://wwwipd.ira.uka.de/~odersky.

One nice aspect of our proposal is that it is very much in the spirit
of the Hindley/Milner system in that ambiguous types are impossible
and we can prove that "well-typed programs cannot go wrong".  Another
nice aspect is that it gives us polymorphic record typing for free -
Ohori's version of it, to be precise. By contrast, current Haskell
classes would give us only monomorphic records.

Maybe not so nice is that some features of current Haskell cannot be
expressed, such as overloaded numbers and functions like
"fromInteger".  But note that these are precisely the features that
seem to cause a lot of problems in current Haskell -- ambiguous types
and the monomorphism restriction, to name just two.

In general, there are some interesting relationships between record
typing and overloading. A good way to look at it is by comparing the
role of record field labels with the role of other identifiers. In ML
this correspondence made is very clear by writing the selection of
field "l" as "#l r", i.e. the label acts like a function
identifier. The way I see it, various record type implementations and
proposals can be classified as follows.

CAML Records &          : labels behave like non-overloaded identifiers.
John Peterson's Proposal  Different record types must have different labels.

SML Records             : labels behave like overloaded identifiers, 
                          using ML's overloading concept. Compiler
                          complains if record type is not statically
                          known.

Ohori's Records         : labels behave like overloaded identifiers, 
                          using our overloading type system. Compiler
                          never complains.

Mark Jones' records     : a special instance of Mark's framework
                          for qualified types. (Mark, I don't have
                          your thesis at hand right now, so please
                          fill in or correct if this is inaccurate).

I don't know enough about Giuliano Procida's proposal to be able to
classify it.

Cheers
 
 -- Martin


Reply via email to