-
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
More struct tuple inference #988
Comments
Yes, I agree. Marking as approved in principle |
For type inference would the typechecker now potentially have to go through the entire method body to settle the (non)structness of a tuple? type C() =
member _.M(x) =
for a, b in x do ()
x |> Array.iter (fun (a, b) -> ())
for v in x do
let a, b = v
// up to this point struct has not been used, so we can't be sure either way yet
v |> fun (a, b) -> ()
// no struct in the last pattern either, so x is an array of "heap" tuples |
@kerams great point, and it sounds plausible. Although I'm wondering if it really matters to have that deferred since it is already identified as a tuple, which is most of the work in simple cases. It would be interesting to see if there are method overloads in the wild that does so on tuple types arguments, in this case I'd say there is more risk of slippery slope in the type checker performance; if your question was geared to that. |
@kerams To stay in line with F#'s top-to-bottom left-to-right type inference, we would probably still need a type annotation at the top. |
Some cases of this can I think be dealt with by changing this use of
However I think the more general case would require putting an inference variable into TupInfo:
This is specifically for the cases like Putting an inference variable into TupInfo is do-able but non-trivial. If somone wants to look at this I can help eith this part. |
It has just came to my mind that tuples type-directed inference will look nice along with collections inference, i.e. let x: ResizeArray = [ 1; 2; 3 ]
let y: struct(int*int*int) = (1, 2, 3) CC #1086 |
More struct tuple inference
The existing way of approaching this problem in F# is:
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are that is will be more difficult to determine whether a tuple is a struct just by looking at the code.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S to M
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: