Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

ijklam
Copy link
Contributor

@ijklam ijklam commented May 24, 2024

Improve underscores in numeric literals and allow hex, octal, binary custom numeric literals

Click “Files changed” → “⋯” → “View file” for the rendered RFC.

See also:

Copy link
Member

@abelbraaksma abelbraaksma left a 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:

RFCs/FS-1142-Extended-numeric-literal.md Outdated Show resolved Hide resolved
RFCs/FS-1142-Extended-numeric-literal.md Outdated Show resolved Hide resolved
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`
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

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).

RFCs/FS-1142-Extended-numeric-literal.md Outdated Show resolved Hide resolved
# 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.
Copy link
Member

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.

Comment on lines +114 to +117
Please address all necessary compatibility questions:

* Is this a breaking change?
Maybe
Copy link
Member

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.

Comment on lines +119 to +123
* 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.
Copy link
Member

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.

Comment on lines +131 to +133
* Colorization

Might need to change the color schema of the numeric literals.
Copy link
Member

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`?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is: no

@abelbraaksma abelbraaksma changed the title Add fs-1142 Extended numeric literal [FS-1142] Improve underscores in numeric literals and allow hex, octal, binary custom numeric literals Jun 1, 2024
@abelbraaksma abelbraaksma changed the title [FS-1142] Improve underscores in numeric literals and allow hex, octal, binary custom numeric literals [FS-1142] Extended numeric literals Jun 1, 2024
Co-authored-by: Abel Braaksma <abel.online@xs4all.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants