fsharp / fsharp/fslang-suggestions
Extend available suffixes for numeric literals
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I propose we extend available suffixes for numeric literals to include all capital and small English alphabets after F. The reason for not allowing A to F is to avoid ambiguities after supporting [hexadecimal integer literals](https://github.com/fsharp/fslang-suggestions/issues/754).
The existing way of approaching this problem in F# is using the current set of suffixes Q, R, Z, I, N and G.
## Pros and Cons
The advantages of making this adjustment to F# are
1. Allowing more numeric literals without suffix collision.
```fs
module NumericLiterali =
let inline FromZero() = System.Numerics.Complex.Zero
let inline FromOne() = System.Numerics.Complex.ImaginaryOne
let inline FromInt32 (n:int) = System.Numerics.Complex(0., float n)
let bigInteger = 1I
let complex = 1i
```
2. Allowing for suffixes that make more sense. For example, with a [System.Half](https://gist.github.com/vermorel/1d5c0212752b3e611faf84771ad4ff0d), we can write
```fs
module NumericLiteralh =
let inline FromZero() = System.Half 0.f
let inline FromOne() = System.Half 1.f
let inline FromInt32 (n:int) = System.Half n
let half = 1h // Not Q, R, Z, I, N or G which don't make sense for a half literal.
```
3. Less rote memorization of rules! (what do QRZING stand for, anyways?)
The disadvantage of making this adjustment to F# is the decreased ability for F#e to add new numeric literals without breaking changes. However, this can be handled with the same way as BigInteger literals where `NumericLiteralI` can be overridden by users.
## Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Related suggestions:
#754
#844
## 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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing related suggestions #754 and #844, since this issue names no files, tests, or implementation entry points. Done would mean the proposed additional numeric-literal suffixes are supported without the hexadecimal ambiguity described here, with the behavior covered by appropriate tests.
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
- 30/100