Overload by return type

BCS none at anon.com
Tue Jan 13 22:09:20 PST 2009


Hello dsimcha,

> Just curious, why doesn't D, and why don't more statically typed
> languages in general, support overload by return type?  I haven't
> exactly thought through all the pros and cons, but at first glance it
> seems like an incredibly useful thing.  What's the catch that I'm
> missing?
> 

Off hand it's one more degree of freedom (and confusion) in trying to figure 
out what type something is.

int bar(char[] c)
int[] bar(char[] c)

float baz(int i)
object baz(int[] i)

auto z = baz(bar("what type is z"));

float foo();
object foo();

z = foo();  // what foo?

Also for all other cases in D (and C, and C++, and C#, and ...) the semantics 
of an expression is not dependent on what expression it is nested under. 
Changing this could have far reaching consequences. 





More information about the Digitalmars-d mailing list