-
Notifications
You must be signed in to change notification settings - Fork 790
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
[Experiment] type resolved arr[idx] #11749
Conversation
In some cases the fix would require adding parens or a dot, like in |
Do I get it right that we'll now allow two different syntaxes with one of them available only on some expressions and only after type checking a file? If yes, I think it adds even more confusion, especially when inferred types change while editing a file. Could we always parse |
Is this is the case? There is no currently valid code
There is currently valid code
No - the
The history here is
So far this is an experiment to check feasability. However, if the experiment doesn't indicate any breaking changes, and we proceed to an RFC, than yes, we'd have two ways to do things and have to work out what to do. Of course we'd only do really this change if we intend
This is not a breaking change (at least, that's what I'm assessing - I don't believe it is so far) Regarding parsing - yes, I expect so. Right now I'm currently not too fussed what the syntax trees are. The implementation technique in the PR at time of writing is
I expect we could make a transformation in the parse phase to change this to an indexing/slicing node in SyntaxTree. Currently this transformation is done in CheckExpressions.fs. I'm not too fussed either way, but once I'm confident the technique works I'll likely move to the former. |
This hits some compatibility and/or completeness problems on compound expressions , e.g. consider that this F# code is allowed today: let g a b = a, b // val g : a:'a -> b:'b -> 'a * 'b
let f (arr:int[]) = g (arr)[4];; Here let f (arr:int[]) = g (arr) [4];; The "high precedence application" limitation only kicks in for identifiers, e.g. the following F# code is disallowed today:
To maintain compatibility here and still allow indexer notation on a non-identifier left-hand-expression in argument position is not going to be possible. This will affect indexing of all these forms: g (f())[i]
g (arr)[i]
g arr[i][j]
g (arr[i])[j]
g arr[*][i] and so on, especially if used in argument position in a curried function. Ideally we would require that people change let f (arr:int[]) = g (some-expr)[4];; to this, with the space: let f (arr:int[]) = g (some-expr) [4];; However that is intrusive on existing code. We could say that compound indexing is not allowed or must use |
I always preferred the dot syntax rather than just in |
Yes, I understand there are advantages, and it is likely existing F# programmers (and functional programmers in general) are happy with However we get a lot of feedback from anyone coming from C#, Python, Java (99% of world's programmers) that this is just very unusual. I do think it interferes with learning. We can discuss on RFC. |
Continued at #11900 |
This is an experiment to allow type-directed
arr[1]
instead ofarr.[1]
for associative lookup and slicing syntaxNote that known type information would always be required, e.g.
because
exists today in F# and infers
x
to be a functionx: int list -> 'a
. In this case we would give a deprecation warning onx[0]
to say "please add a space indicating function application or a type annotation indicating array loop" i.e.x [0]
for the former