Scalable and Continuous

Matt Harden matth@ninenet.com
Sat, 17 Feb 2001 22:28:39 -0600


Dylan Thurston wrote:
> 
> On Fri, Feb 16, 2001 at 10:21:57PM -0600, Matt Harden wrote:
> > Marcin 'Qrczak' Kowalczyk wrote:
> > > Wed, 14 Feb 2001 23:27:55 -0600, Matt Harden <matth@ninenet.com> pisze:
> > > > such defaults would only be legal if the superclass did not define
> > > > a default for the same function.
> > >
> > > Not necessarily. For example (^) in Num (of the revised Prelude)
> > > has a default definition, but Fractional gives the opportunity to
> > > have better (^) defined in terms of other methods. When a type is an
> > > instance of Fractional, it should always have the Fractional's (^)
> > > in practice. When not, Num's (^) is always appropriate.
> > What happens if classes A and B are superclasses of C, all three
> > define a default for function foo, and we have a type that's an instance
> > of A and B, but not C, which doesn't override foo?  Which default do we
> > use?  It's not only a problem for the compiler to figure out, it also
> > quickly becomes confusing to the programmer.
> 
> (Presumably you mean that A and B are subclasses of C, which contains
> foo.)  I would make this an error, easily found by the compiler.
> But I need to think more to come up with well-defined and uniform
> semantics.

No, I meant superclasses.  I was referring to the possible feature we
(Marcin and I) were discussing, which was the ability to create new
superclasses of existing classes.  If you are allowed to create
superclasses which are not referenced in the definition of the subclass,
then presumably you could create two classes A and B that contained foo
from C.  You would have to then be able to create a new subclass of both
of those classes, since C is already a subclass of both.  Then the
question becomes, if they both have a default for foo, who wins?

My contention was that the compiler should not allow a default for foo
in the superclass and the subclass because that would introduce
ambiguities.  I would now like to change my stance on that, and say that
defaults in the superclasses could be allowed, and in a class AB
subclassing both A and B, there would be no default for foo unless it
was defined in AB itself.  Also C would not inherit any default from A
or B, since it does not mention A or B in its definition.

If this feature of creating new superclasses were adopted, I would also
want a way to refer explicitly to default functions in a particular
class definition, so that one could say that foo in AB = foo from A.

BTW, I'm not saying this stuff is necessarily a good idea, just
exploring the possibility.

Matt Harden