[Haskell] PROPOSAL: class aliases
S.M.Kahrs at kent.ac.uk
Thu Oct 13 07:57:10 EDT 2005
> I've considered this before, but never done anything about it because
> superclasses are so close. Specifically, what is the difference between
> (i) class (C a, D a) => CD a
> (ii) class alias CD a = (C a, D a)
The difference is that (i) is, in a sense, generative - because
you still have to declare a type to be an instance of CD even if
it is one of both C and D.
That is not only inconvenient it can even create problems,
for modular program development, as class instances always cross
module boundaries [which is a wart]. So if there are two different
modules in your project needing a type to be an instance of CD,
you need to find a single place where to put that instance declaration.
Frankly, as long as there is no way to limit the scope of an instance
it would probably even make sense to treat method-less classes as class
synonyms anyway, i.e. ones that do not require instances.
Though ways of limiting the scope of class instances is probably
a change quite a few people would like to see, so such a change
would inhibit a move in that direction in the future.
More information about the Haskell