Re: Covariant Return Types

Daniel Bonniot <[email protected]> Wed, 25 Feb 2004 02:21:51 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
>    package a;
>    class A { }
>    class B extends A { }
>    A self(A a) = a;
>    B self(B b) overrides A self(A) = b;
>
>    void main(String [] args) {
>        let x = self(A); // syntax?
>        let y = self(B); // syntax?
>        println(x == y); 
>    }
>
>Do I get "true" or "false"? 
>
You get: "A is not a value" a the first line with the comment :-)

What do you mean? self(new A()) ?


>So, then we can conclude that visibility modifiers only make sense for method
>declarations, not for method implementations, right? So that:
>  
>
Right.

>I agree. Would this be a proper description of the (future) method model in Nice?:
>
>Every method has exactly one type and zero or more implementations. A method can
>be specialized by other methods; when this is done, the implementations of all
>the specializing methods are considered also to be implementations of the
>specialized method. For a method M to be specialized by a method N, for every
>nth parameter P(M,n) and P(N,n), it must be true that P(M,n) : T, P(N,n) : U
>implies U <: T, and if V and W are the return types of M and N, respectively,
>then W <: T. Methods are dispatched to a particular implementation based on the
>types and/or values of the actual parameters.
>  
>
Yes, that sounds right. Thanks for the formalization!

Daniel



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click