-
Notifications
You must be signed in to change notification settings - Fork 21
-
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
Allow expr[idx] as indexer/slicing syntax #1053
Comments
This reminds me of another suggestion with the same motivation:
Maybe it is time to revisit: #644 Namely to allow |
I agree with @amieres if both are breaking changes, I suffered more from having to add parens everywhere for stuff like |
Completed in F# 6 |
F# has used
expr.[idx]
as indexing syntax. This was inherited from OCaml, which uses it for string indexing lookup. However in F# the notation has always been type-directed, so a well-known strong indexable type has been needed forexpr
.Based on the experiment at dotnet/fsharp#11749 I propose we allow
expr[idx]
as indexer/slicing syntax and normalize this as the preferred indexing syntax from F# 6.0 onwards.This is to make learning F# easier and allow simpler migration of existing code.
As with any indexing today known type information is required, e.g.
This is because
exists today in F# and infers
x
to be a functionx: int list -> 'a
. In this case we woll give a deprecation warning onx[0]
to say "please add a space indicating function application or a type annotation indicating indexing" i.e.let f arg = arg [0]
for the former.Technically this is not a breaking change to existing well-typed code (because we can use types to disambiguate between a function and something supporting indexing). However, as a matter of policy we will emit warnings to recommend small adjustments to existing code to properly disambiguate, by introducing spaces for function application. Informational recommendations to change
expr.[idx]
toexpr[idx]
will also be given.I will put the details in an RFC
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
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: