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 for expr.
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.
let f (arg: int[]) = arg[0], arg[1]
This is because
exists today in F# and infers x to be a function x: int list -> 'a. In this case we woll give a deprecation warning on x[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] to expr[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.
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
xto 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.