Re: Nice multiple dispatch details

[email protected] Thu, 21 Feb 2008 00:16:37 +1300
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Thanks Daniel, that makes it a lot clearer!

Now, in terms of dynamic (multiple or single) dispatch:
The concept is that at compile time there is a known set of 
alternative method bodies for each call site. At runtime, the most 
appropriate body is chosen from this set, depending on the dynamic 
types of the arguments involved in the call. In some languages, this 
set is called a generic function. In Nice, it is a method 
declaration that has a set of alternative method 
implementations/bodies.

In some languages (at least CLOS, Dylan, Cecil), a method body 
belongs to one generic function. In Nice it can belong to one or 
multiple declarations. 

I hope I got that right, correct me if I'm wrong please ;-)

cheers,
Radu


On Wed, 20 Feb 2008, Daniel Bonniot wrote:
> 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/
> _______________________________________________
> Nice-info mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nice-info

-------------------------------------------------------------------------
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/