Re: Nice multiple dispatch details
"Daniel Bonniot" <[email protected]> Wed, 20 Feb 2008 09:27:19 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
For clarification: there are two concepts: 1) method declaration, for instance: <T> String toString(!T); and String toString(Vehicle); It has a return type, possible a contract, no code. 2) method implementation (or "method body" or "alternative"), for instance toString(Car a) = "..."; It has no return type nor contract, but some code. A method implementation belongs to one (or several, see below) method declaration, for which it represents the code to execute in a certain context. A method declaration m2 can override another method declaration m1. This happens when m2 is more specific than m1. It can in particular have a more specific return type. In this case, all implementations of m2 will also be implementations of m1. On Feb 19, 2008 11:29 PM, <[email protected]> wrote: > There's one thing that I am a bit confused about. > > The code: > String toString(Vehicle a) = "a vehicle"; > toString(Car a) = "a car"; > > gives me this warning: > > ~/ca/corpus/nice/test1/main.nice: line 23, column 8: > warning: This method overrides <T> java.lang.String toString(!T) > You should make this explicit, either by omitting the return type > or by using the 'override' keyword. > > What does 'overrides' mean here? If a method overrides another, does > it imply that it is part of the same method (dispatch) group? > So, in this case, is toString(test1.Vehicle a) part of toString(!T)? > Is toString(Car a) part of toString(!T)? > > Additionally, the compiler seems to create a new method group > toString(test1.Vehicle a) with the two alternatives: > toString(test1.Car a) > toString(test1.Vehicle a) > > >From this, it appears that a method body can be in multiple method > groups. Is this correct? > > So for this call site: > toString(new Vehicle()); > > the method group would be: > toString(test1.Car a) > toString(test1.Vehicle a) > > > while for this call site: > toString(new java.lang.Object()); > > the method group would be: > toString(!T) > toString(test1.Car a) > toString(test1.Vehicle a) > > Is this correct? Yes, this is correct :-) Daniel ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/