Do interfaces make sense in multiple dispatch languages?

[email protected]
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Please read "Designing with interfaces"
http://www.javaworld.com/javaworld/jw-12-1998/jw-12-techniques.html which
attempts to justify Java's choice to have interfaces instead of multiple
inheritance. But, the diamond problem for interfaces exists in Nice. Consider:

     class ClassTop { }
     class ClassLeft  extends ClassTop   { }
     class ClassRight extends ClassRight { }

     int classFoo(ClassTop t);
     classFoo(ClassLeft  l) = 1;
     classFoo(ClassRight l) = 2;

     interface InterfaceTop { }
     interface InterfaceLeft extends InterfaceTop { }
     interface InterfaceRight extends InterfaceTop { }
     int interfaceFoo(InterfaceTop t);
     int interfaceFoo(InterfaceLeft t) = 1;
     int interfaceFoo(InterfaceRight t) = 2;

     class ClassBottom extends ClassLeft, ClassRight { }
     class InterfaceBottom implements InterfaceLeft, InterfaceRight { }

     void main(String [] args) {
         ClassTop ct = new ClassBottom();
         classFoo(ct);     // ambiguous
         InterfaceTop it = new InterfaceBottom();
         interfaceFoo(it); // ambiguous
     }

Given the PropertySyntax proposal to access fields only via methods combined
with the re-introduction of the diamond problem, it seems that implementing
multiple class inheritence will not introduce any problems (by generating a Java
interface for each Nice class as well as a Java class for each non-abstract Nice
class, and using compiler-generated copy-down inheritence of fields). Therefore,
the concept of interface can be replaced in Nice without introducing any ill
effects from a language semantics viewpoint. The only issue would be a special
case for Nice classes that extend Java classes: a Nice class can extend any
number of Nice classes as long as all of those its superclasses transitively either:
    a) extend another Nice class, or
    b) extend java.lang.Object.
Additionally, a Nice class can extend at most one class that has a non-Nice
superclass that is not java.lang.Object.

It seems the above idea is too simplistic but I can't find any obvious problems
with it. This proposal also seems to leave open the possibility of
distinguishing between classes and types in the language at a future date.

- Brian




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.