Re: Object or <T> parameters

Daniel Bonniot <[email protected]> Tue, 24 Feb 2004 09:55:15 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
[email protected] wrote:

>Shouldn't the type system ensure that the following example doesn't compile:
>
>void my_println(Object o) {
>	println(o);
>}
>
>void main(String [] args) {
>	let a = () => "hello";
>	my_println(a);
>}
>
>It seems like we are much more likely to want to have written:
>
>void main(String [] args) {
>	let a = () => "hello";
>	my_println(a());
>}
>  
>
I think this is pretty specific to the fact that toString is available 
on any value, and therefore println also.

To get more static checking, it would be interesting to have a 
"Showable" (hello magnus!) or otherwise named abstract interface, so 
that classes clan declare if they implement in a meaningful way a method 
that represents their instances as strings. One obstacle to that is the 
variance issue, but that will be solved eventually ;-)

>In particular, I think that arrow types should not be considered subtypes of
>Object. Then, we have:
>  
>
I think that would be giving the wrong message. Hey, in Nice, functions 
are not really objects, they are not like other values, they are not 
really first class!

Now, if we say that functions are not Showable, that makes perfect sense.

>If you try to compile a function like:
>    <Object T> void doSomething() { }
>The compiler reports:
>    Object is not a class
>This is strange because "Any" is not a class either but it is allowed. Isn't
>"Any" the same kind of thing "Object" is?
>  
>
Any is nothing at all, really ;-)
It's a piece of syntax, hapilly ignored after the parser has read it. I 
would probably recommand to simply wite <T> for an unconstrained type 
parameter. Would dropping 'Any' make things clearer?

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