-
Notifications
You must be signed in to change notification settings - Fork 21
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
Hexadecimal, octal and binary custom numeric literals #754
Comments
I don't like this.. Because not all platforms support |
I'm talking about custom numeric literals, which are user-defined. Defining colors is one of the use cases if the mechanism is extended to support binary, octal and hexadecimal literals. |
That makes a lot more sense. I was drawn completely by |
Using the current way, of course! module NumericLiteralR =
//let FromZero() = System.Drawing.Color.FromArgb(0)
//let FromOne() = ...
let FromInt32 n = System.Drawing.Color.FromArgb(n)
//let FromInt64 n = ...
//let FromString s = ...
let expected = System.Drawing.Color.FromArgb(123)
let value = 123R
expected = value module NumericLiteralR = begin
val FromInt32 : n:int -> System.Drawing.Color
end
val expected : System.Drawing.Color = Color [A=0, R=0, G=0, B=123]
val value : System.Drawing.Color = Color [A=0, R=0, G=0, B=123]
val it : bool = true The problem is that hexadecimal is unsupported, but it is the standard representation.
|
wow, I didn't know that it could be done like this! |
Yes, To be honest the use of custom numeric literals don't seem widespread enough. They being limited to only integral types may be a possible reason. We should expand support for these, e.g. hexadecimal representation. |
I wonder if type providers are a good way to make "literals". Essentially being a passthrough but with a transformation and compile time check |
I'm ok with this - it should be possible to use hex, octal and binary custom literals with the allowable suffixes @Happypig375 Could you update the examples to make it more obviouus that this is not about "Color", e.g. make the sample a full proposed example. |
Hexadecimal, octal and binary custom numeric literals
I propose we allow first-class support of colors.
The existing way of approaching this problem in F# is either through functions taking non-decimal strings or converting from integers.
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantage of making this adjustment to F# is an implementation in the F# compiler converting hexadecimal, octal and binary strings to decimal strings to call
FromString
would probably be required.Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: