Re: Do interfaces make sense in multiple dispatch languages?
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
Quoting Isaac Gouy <[email protected]>: > > the diamond problem for interfaces exists in Nice. > > like this? > void main(String [] args) { > let it = new InterfaceBottom(); > println( interfaceFoo(it) ); > } > > Ambiguity for symbol interfaceFoo. Possibilities are : > nice.lang.int interfaceFoo(InterfaceRight t) > nice.lang.int interfaceFoo(InterfaceLeft t) Exactly. > (Same as with Scala's Traits) > > the concept of interface can be replaced in Nice without introducing > > any ill effects from a language semantics viewpoint > > Shouldn't we ask what we expect the benefits of multiple inheritance to > be? To quote from that JavaWorld article > http://www.javaworld.com/javaworld/jw-12-1998/jw-12-techniques_p.html What are the differences between abstract classes and interfaces in Nice?: * A class can only subclass one other class but can implement many interfaces. * An interface cannot extend any class. * An interface cannot define any fields. What are the similarities between an abstract class an an interface? * Methods can be define to operate on interface types and class types. * Methods can be specialized for both types. * Neither classes nor interfaces define/declare any methods. Now, how do the differences between abstract classes and interfaces benefit users of the language? The first difference I think the only difference that might be useful in practice is the third one (interfaces cannot define fields) because you don't have to worry about the diamond problem for fields with interfaces. But the diamond problem already exists for methods so maybe a more general solution is needed. If a more general solution is given, then it might obviate the need for interfaces. Note that in Nice an interface is just an abstract type since they don't "contain" any methods. You could change the syntax for interfaces from: interface Foo extends Bar { } class CFoo implements Foo { ... } to: type Foo <: Bar; class CFoo <: Foo { ... } or: abstract type Foo <: Bar; class CFoo <: Foo { ... } I would think it makes more sense to think of it this way. In particular, "class CFoo implements Foo" does not makes sense because there is nothing in interface Foo to "implement"; interfaces in Nice are always empty. > > "I spent five years programming in C++, and in all that time I had > never once used multiple inheritance. Multiple inheritance wasn't > against my religion exactly, I just never encountered a C++ design > situation where I felt it made sense. When I started working with Java, > what first jumped out at me about interfaces was how often they were > useful to me." One can use C++ superclasses like traits using a restricted form of the "mixin" pattern. So, he apparently would not have any use for traits either. Perhaps, he would not have any use for dispatching based on interface types either? - 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