Ketil Z Malde
10 Dec 2001 10:32:48 +0100
David Feuer <firstname.lastname@example.org> writes:
> 1. Why can't [instances] be hidden in module imports/exports?
The way I see it, an instance declaration is an assertion that a
certain data type supports a certain set of operations. Thus, if the
data type and the operations on it are in scope, it makes sense for
the class instance to be, too.
(This leads to the question of why we need to have instance
declarations at all :-) (My guesses would be: compiler
implementation issues, code clarity, error detection, partially
Problems arise when a data type needs to be instantiated twice in the
same class, but with different operator implementations. (I.e. you
have a data type which prints differently according to which module
This would, I think, be a problem in most languages, think of deriving
a C++ class twice from the same base class while providing different
overrides for the functions.
I'm not entirely convinced it's an issue that needs a better
resolution than the language provides today. (There's a diminishing
returns effect when adding language features, and at some point, the
increased complexity of the language doesn't make it worth it, IMHO.)
> 2. Why can't you simultaneously declare a type to be an instance of
> multiple classes?
Why does it matter?
> class C1 t where a::t->t
> class C1 t => C2 t where b::t->t
> instance C1 T, C2 T where
To me, it'd make more sense to provide
class C1 t where a :: t -> t
class (C1 t) => C2 t where b :: t -> t
instance C2 T where
a = ... -- implicitly instantiating C1
b = ...
and avoid long instantiation chains. But that too is IMHO a minor issue.
If I haven't seen further, it is by standing in the footprints of giants