fsharp / fsharp/fslang-suggestions
Better interop with `System.Index` and `System.Range`
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
The .NET runtime will add new methods taking `System.Index` and `System.Range` in the future, like https://github.com/dotnet/runtime/issues/321.
I propose we allow the range operator to be interpreted as `System.Index` and `System.Range`.
```fs
let a : System.Range = { 4..^1 }
```
The existing way of approaching this problem in F# is
```fs
System.Range(System.Index 4, System.Index (1 - 1, true))
```
## Pros and Cons
The advantages of making this adjustment to F# are
1. Interoperability
2. Conciseness
3. Convenience
The disadvantages of making this adjustment to F# are that this will create an inconsistency where `{ 1 .. 4 }` is a `seq` but this expression can also be interpreted as a `System.Range` upon adding a type annotation, which is surprising. However, there is already precedence where `"%d"` is a `string` on its own but can be interpreted as a `PrintfFormat<_, _, _, _>` upon the addition of a type annotation.
## Extra information
Estimated cost (XS, S, M, L, XL, XXL): S to M
Related suggestions: None
## Affidavit (please submit!)
Please tick this by placing a cross in the box:
* [x] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
* [x] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this
## For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.
Contributor guide
No contributing guide indexed for this repository
Research direction
No repository files, tests, or entry points are named. Start by reviewing the proposal and the linked .NET runtime issue, then locate the F# compiler handling for range expressions and existing tests for range syntax. Done means the annotated examples support System.Index and System.Range without changing existing sequence-range behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100