Who needs Ord for Sets and Maps anyway?
cgibbard at gmail.com
Thu Jan 19 10:56:42 EST 2006
On 19/01/06, Johannes Waldmann <waldmann at imn.htwk-leipzig.de> wrote:
> PS (I know this is heresy but - can we please in Haskell-0X rename
> "class" to "interface" so that the non-Haskell world knows what we're
> talking about. You know if the mountain's not gonna walk to the prophet,
> then ...) (note that I'm currently not proposing to rename "data" to
> "class". But looking at GADT data definitions still makes me wonder...)
Typeclasses are about as much unlike Java interfaces as they are
unlike Java classes. Typeclasses are not types, like interfaces are in
Java (at least, when I learned Java, I'll admit I haven't been
following progress too closely). Typeclasses (at least in modern
Haskell), are allowed to have arbitrarily many type parameters as well
as functional dependencies between those parameters, whereas
interfaces in Java are something that each class is permitted to
implement, but they do not tie multiple classes together.
Further, functions in Haskell are permitted to require that some types
involved satisfy any number of classes, whereas with interfaces,
classes implement some interfaces, but only one interface at a time
can be mentioned when it comes to using them.
For example, in Haskell, I can write:
f :: (Ord a, Read a) => String -> String -> a
f xs ys = max (read xs) (read ys)
Whereas in Java, this kind of requirement that a type implement
multiple interfaces seems harder to specify (correct me if I'm wrong,
it's been a few years since I wrote any Java code).
If I recall correctly, interfaces in Java are not permitted to provide
default implementations of methods which they declare (and that's one
of the major things separating them from classes), whereas in Haskell,
we are permitted to define default method implementations in classes,
which can be overruled in the instances.
In any event, I think it's dangerous when coming to a new language to
expect that the terms mean the same thing at all. "Class" means
something different to a Haskell programmer than a Java programmer,
and that's fine. So do most other words. :) Haskell isn't claiming to
be an OO language, so we don't have to align with OO terminology.
That said, 'interface' or perhaps 'predicate' or 'relation' seem like
slightly better words than 'class' here, purely from an English
language perspective, but the term 'class' does have a justification,
and I think it's already blatantly obvious to new Haskell programmers
that Haskell classes are not too much like OO classes, even if the
terminology is similar. Is the small benefit really worth the trouble
of altering all the literature and code to change the name?
More information about the Libraries