Re: Method overrides and covariant return types

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

>>By experience, we know that people _will_ write implicit overriding,
>>and expect it to work, even though the documentation shows that
>>method implementations have a different form. 
>>    
>>
>
>IMO the language user doesn't benefit from having 2 different ways to
>express explicit overriding - override keyword & yet another method
>implementation form. Choose one - override keyword.
>  
>
One way to look at it is that there is only one form of method 
implementation, with an optional part for overriding the return type:

[ override /type/ ] /method-name/(...) { ... }

Of course you could require that 'override' be present in all cases, but 
that adds a significant syntactic overhead. The redundancy of the type 
is not even useful, since it is already embodied in the code 
implementing the method.

The short form feels quite elegant when you write, for instance:

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

Daniel