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

Extend available suffixes for numeric literals #845

Open
5 tasks done
Happypig375 opened this issue Mar 8, 2020 · 0 comments
Open
5 tasks done

Extend available suffixes for numeric literals #845

Happypig375 opened this issue Mar 8, 2020 · 0 comments

Comments

@Happypig375
Copy link
Contributor

Happypig375 commented Mar 8, 2020

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.

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.
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
  1. Allowing for suffixes that make more sense. For example, with a System.Half, we can write
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.
  1. 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:

  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants