-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid type inference defaulting to object in absence of evidence #885
Comments
I'm so looking forward to that one... again bumped into it no later than yesterday =| |
@smoothdeveloper just pointed me this he found this issue here: dotnet/fsharp#6605 While working on the compiler |
This incorporates the motivating examples from fsharp/fslang-suggestions#885 .
Does this amount to declining this suggestion? That only does Actually I think this suggestion is too small and should be enlarged to "Avoid type inference which makes unprovable conclusions", including avoids inferring |
There are many situations where type inference has no enough evidence to decide the type and in absence of the inline keyword (sometimes even with it) defaults to its defaults value, which typically is object, except for math operations which is int.
Examples:
This is already obvious for experienced F# users, but take the example of the addition, it's been asked for almost every newcomer in SO, Slack, forums.
But the problem doesn't end there, this apparently isolated behavior cause many headaches when working with complicated type inference problems.
The existing way of approaching this problem in F# is ... there's no way around it while maintaining genericity.
There are different things we can put in place to avoid this common problem:
1) Remove the "default default to obj". Optionally defaults to obj can be specified manually in the compiler and we can make default keyword available to the user.
2) Allow user to use the default keyword in trait-calls, adding a syntax to set no default. This would be a way to gain gradually control over the situation, without introducing a breaking change.
Pros and Cons
The advantages of making this adjustment to F# are more control over type inference, consistency with other areas of type inference, like value restriction where in absence of evidence the compiler asks the user what to do.
The disadvantages of making this adjustment to F# are introduction of another error that the user has to understand what it means. Still I think this is better than getting an
obj
inferred silently.It's work.
(1) is easy to implement but it would introduce a breaking change.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): Depending on options, from XS to M
Related suggestions: It seems to me that this situation is getting worse with the coming dotnet/fsharp#6805
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: