[FS-1142] Extended numeric literals#770
Conversation
abelbraaksma
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
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`? |
Co-authored-by: Abel Braaksma <[email protected]>
|
I am marking this RFC as a draft as there are many unresolved comments from previous review. |
Improve underscores in numeric literals and allow hex, octal, binary custom numeric literals
Click “Files changed” → “⋯” → “View file” for the rendered RFC.
See also: