Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Consider the return type in overload resolution #820
Consider the return type in overload resolution
I propose we add a mechanism (attribute or language construct) to consider the return type in overload resolution.
The existing way of approaching this problem in F# is to add a dummy parameter with the type of the return type and call the function with its default value.
Pros and Cons
The disadvantages of making this adjustment to F# are:
Estimated cost: S-M
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For C# 9 I read somewhere that they're going to support return type covariance (returning a more specific type than expected at the call site, though I didn't check the details). It might be related, not sure, I don't fully grasp your proposal yet ;).
@gusty for clarification, what kind of code would currently not compile, and after this change would compile successfully? Could you elaborate with some examples?
@gusty I would love this feature very much. However why an additional lang construct or attribute?
An easy example, all generic applicatives and monads require a set of overloads, based solely on the return type. See here an example.
A more complex scenario: many overloaded functions improve type inference if the return type is taken into account.
Hope you're not willing to forbid overloads ;)