-
Notifications
You must be signed in to change notification settings - Fork 143
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
[FS-1142] Extended numeric literals #770
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @Tangent-90! Some comments and some food for thought below:
This RFC will allow the following things: | ||
|
||
- Underscores in numeric literals after prefix and before suffix like `0x_1` or `1_l` or mixed them up like `0x_1_l`. | ||
- Hexadecimal, octal, binary and floating point custom numeric literals like `0x1I` or `1.0G` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel strongly that we should put the floating point part (possibly with decimals) in a separate RFC. It is significantly different to extend the domain, vs, just updating a bit of syntax (i.e., 0x
and 0b
are just syntax).
Can you also expand if the previous point applies to custom literals as well, and if, in that case, the trailing I
or G
can have an underscore before it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. there can be some underscores before I
or G
|
||
# Motivation | ||
|
||
Make the language more consistent and easier to read. Enhance the custom numeric literals feature by supporting not only integers but also floats. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
floats: please put that in a separate RFC (and later also, PR).
# Alternatives | ||
|
||
- For number prefix (`0x`, `0o`, `0b`) before integer custom numeric literals, we might introduce a new `FromIntegerString` to avoid the break change. | ||
- Or firstly parse it to `bigint` then `ToString` to obtain a literal without prefix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a much better suggestion. In fact, you don't even have to do that. Conversion is rather trivial and can be done on-the-fly.
This would certainly be my preference and would avoid any burden on people writing custom numerals modules.
Please address all necessary compatibility questions: | ||
|
||
* Is this a breaking change? | ||
Maybe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to avoid this, if possible, see my comments and trains of thought above.
* What happens when previous versions of the F# compiler encounter this design addition as source code? | ||
Can write numeric literal module with new functions in the source code, but cannot use these new numeric literal grammar. | ||
|
||
* What happens when previous versions of the F# compiler encounter this design addition in compiled binaries? | ||
Cannot use the new numeric literal grammar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revisit this after we have a decision.
* Colorization | ||
|
||
Might need to change the color schema of the numeric literals. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably not going to be a problem, as the syntax highlighter uses the parser results. If the parser says something is a numeric literal, it will be colored as such.
But certainly something to test before merging this change
|
||
# Unresolved questions | ||
|
||
- Should we introduce a new `FromIntegerString` or use any way to remove number prefix from custom integer literal string passed to `FromString`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion is: no
Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
Improve underscores in numeric literals and allow hex, octal, binary custom numeric literals
Click “Files changed” → “⋯” → “View file” for the rendered RFC.
See also: