Re: Why can't overloads take into account the return type.
- From: Helge Jensen <helge.jensen@xxxxxxx>
- Date: Wed, 18 May 2005 10:37:56 +0200
Jon Skeet [C# MVP] wrote:
For some reason language writers seem to like to keep things consistant with previous languages.
Overloading on the return type means that you cannot determine the type of an expression without looking at it's context.
That is undesireable because it prevents using compositional recursion to evaluate the type of the expressions of the program.
As a small taste of the problem, given definitions:
X f(Y); Y f(X); X x; Y y;
Which error would you give on:
y = f(f(x))
Hint: there are two possible errors:
1: cannot covent argument 1 of "X f(Y)" from type X to type Y 2: cannot assign type X to type Y
Depending on whether you overload by the arguments or the return-type.
Besides, if you wish to overload on the "return-type", just use:
f(out X x, Y y); f(out Y y, X x);
I suggest trying to write a staticly typed compiler to get to really understand this problem.
-- Helge Jensen mailto:helge.jensen@xxxxxxx sip:helge.jensen@xxxxxxx -=> Sebastian cover-music: http://ungdomshus.nu <=- .
- Follow-Ups:
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Mike Schilling
- Re: Why can't overloads take into account the return type.
- References:
- Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Alan Pretre
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Alan Pretre
- Re: Why can't overloads take into account the return type.
- From: John B
- Re: Why can't overloads take into account the return type.
- From: Chris Priede
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Daniel O'Connell [C# MVP]
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Daniel O'Connell [C# MVP]
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Jon Skeet [C# MVP]
- Re: Why can't overloads take into account the return type.
- From: Michael C
- Re: Why can't overloads take into account the return type.
- From: Jon Skeet [C# MVP]
- Why can't overloads take into account the return type.
- Prev by Date: Re: C# very optimisation
- Next by Date: Automating Managed WinForms Applications....
- Previous by thread: Re: Why can't overloads take into account the return type.
- Next by thread: Re: Why can't overloads take into account the return type.
- Index(es):
Relevant Pages
|