Re: Why can't overloads take into account the return type.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 <=-
.



Relevant Pages

  • Re: How Do CLs Macros Differ from Schemes?
    ... context-sensitive grammars are of little help in programming ... languages and are not widely used at all. ... What is a context-sensitive grammar? ... In a context sensitive grammar we might have stuff like. ...
    (comp.lang.lisp)
  • Re: parser
    ... and by no means is Java some obscure language... ... Java bundles a high-performance concurrent garbage ... I would advocate C# over Java in this context though, ... functional programming languages. ...
    (comp.programming)
  • Re: About context sensitivity.
    ... I heard of Anders Heljsberg eplaining the idea of Data Programming. ... This means semantic net based Semantic ... Level context programming language available? ... > sensitivity and if some programming languages exist that target .NET. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Where does the drive to syntax come from?
    ... I don't know of any evidence that more syntactic variation leads to ... evidence that syntactic ambiguity is difficult to process. ... then people would use much simpler languages ... experiments of which I'm aware have studied semantic context, ...
    (comp.lang.lisp)
  • Re: Christian nation? Not now, not ever
    ... word meanings may be known, idioms, syntax, context, etc are ... for a specific audience. ... specific audience which shared the times and languages. ... the theme and flow and put it into the context for which it was ...
    (rec.sport.football.college)