|
Perhaps the most obvious candidate here is Haskell's
system of type classes, which provide support
for user defined overloading. In this talk, I will give
some examples to illustrate how type classes can be used
to promote modularity and extensibility and to reduce the
coupling between different sections of a program. (However,
there's a judgement call here. Some Haskell programmers
have used the class mechanisms to simulate aspects of
powerful module systems, like those of SML, perhaps because
of weaknesses in the Haskell module system, or perhaps because
the role of type classes in Haskell has been overemphasized.
I consider such things to be an abuse of type classes, but
it's subjective, and I won't go into it any further here.)
So what is a type class? Essentially, it's just a set
of types. (Think of "class" in the sense of set theory
rather than object-oriented programming!) The picture here
shows the set of all monotypes, represented by the kind *.
Inside that is the subset of equality types, Eq, which includes
things like integers and booleans, but excludes things like
functions and the computable reals. What makes the Eq class
special is that all of its members have something in common:
they all support an effective algorithm for structural
equality.
Next...
|