Re: Method overrides and covariant return types

Daniel Bonniot <[email protected]> Sat, 06 Mar 2004 12:42:17 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Isaac Gouy wrote:

The redundancy of the type is not even useful, since it is already
embodied in the code implementing the method.

I disagree. In languages without explicit type information the one
thing that everyone adds, as a comment, is the return type.

As the method definition can be in one file, and the method
implementations are spread across other files, it would certainly be
useful to show the return type in each place.

I didn't mean that it's never useful to indicate the return type. I
meant that there are situations where it's useful to omit it, namely
when the implementation is next to the declaration. Moreover, if the
return type is useful as documentation to the reader, then it can be
the editor's job to show it together with the whole declaration's type,
contract and doc comment.

And it's unclear to me why it should be an error to do so:
int fact(0) = 1;

At the moment fact(0) is treated as a method implementation, not an
(overriding) method declaration. So you cannot specify a return type.
(If you were allowed to covariantly override the return type, this
could only be used by the compiler if it were checking what _value_ you
pass to the method, not merely its type.) Probably this distinction
will be removed in the future. I just thought that correctly handling
overloading was more urgent.

int fact(int n) requires n>=0;
fact(0) = 1;
fact(n) = n * fact(n - 1);

Perhaps it would be useful to consider an example where the parameter
type actually allowed extension?

My point was that it is pleasant to be allowed to use this short form
of method implementation. That's not specific to value dispatch. If we
consider that this is the case where 'override type' can be
omitted, if fits well with the "long form". Do you object to that?

Daniel

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click