Skip to content

Underscores in numeric literals after prefix and before suffix #718

@chadunit

Description

@chadunit

I propose we allow underscores in numeric literals after the base prefix and before the type suffix.

Currently, leading/trailing underscores in numeric literals are not allowed after the prefix or before the suffix. This lessens readability because the leading and trailing groups blend into the additional characters and lose their visual "shape".

0b1111_1111uy // valid
0b_1111_1111_uy // not valid (proposal to allow)

Is there a rationale for disallowing these underscores? According to RFC FS-0005, the rules seem to be modeled after a pre-existing ruleset from Java. There don't seem to be arguments for or against this specific restriction so it's not clear if it was actively favored or if it just came along for the ride. (Thus I don't believe this necessarily counts as "already been decided" per the affidavit below.)

Also note that some other languages have chosen to be less restrictive:

0b_1111_1111 // C# 7.2 - leading underscore valid
0b_1111_1111_u8 // Rust - leading and trailing underscore valid

(C# reference, Rust reference)

Pros and Cons

The advantages of making this adjustment to F# are: better readability

The disadvantages of making this adjustment to F# are: none that I know of

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: F# RFC FS-0005 - Underscore Literals

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • 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:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions