fsharp / fsharp/fslang-suggestions
Allow to use subscript numbers in F# code
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I sometimes work with scientific code and it's inconvenient in some cases. When I program a formula, it is very convenient to enter it as is. For example, there's a formula `Z₀ = E / H` (the first real example I found in my notes when performing calculations related to the [impedance of free space](https://en.wikipedia.org/wiki/Impedance_of_free_space)), which I'd like to see in my code as it looks here. But unfortunately, in F# I have to write it as `Z_0 = E / H`, since `Z₀` doesn't compile ([link to Sharplab](https://sharplab.io/#v2:EYLgtghglgdgNAGxAMwM5wC4iguATEAagB8B7ABwFMYACAZQE9UNKwBYAKAUoxoFEaAXhoBGAAyduvABJCaAVglceNAFqAAgjkCA9DWmcgA=)).
> ```
> error FS0010: Unexpected character '₀' in binding. Expected '=' or other token.
> ```
**I propose we** add a possibility to use subscript numbers in F# code, such as:
```fsharp
let E = 10
let H = 50
let Z₀ = E / H // this!
```
Notably, it's possible to use subscript characters such as `ₖₒₐₗₐ`, but not numbers.
**The existing way of approaching this problem in F# is** to use a notation of `Z_0` instead, which doesn't look that good.
## Pros and Cons
**The advantages of making this adjustment to F# are**: there will be easier to write and, more importantly, read code based on formulas in scientific calculations.
**The disadvantages of making this adjustment to F# are**: well, it'd be easier to abuse this feature and name certain symbols in
- either a confusing way
- or in a way that makes it harder to reuse the values in other languages (say, C# doesn't allow `Z₀` either).
Note that this is about subscript numbers for now, and not superscripts. Superscripts would be more confusing, since `E²` is easy to mix with `E ** 2`.
## Extra information
**Estimated cost (XS, S, M, L, XL, XXL):** XS.
**Related suggestions:** none that I was able to find.
## 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
Start by reviewing the proposed F# syntax and the SharpLab example in the issue, including the contrast between subscript letters and numbers. Determine the language-design and compiler work needed to accept bindings such as Z₀, then validate the accepted and rejected identifier forms with compiler tests; done means the proposal is resolved and the behavior is specified and tested.
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
- 35/100