fsharp / fsharp/fslang-suggestions

Hexadecimal, octal and binary custom numeric literals

Open
#754 8 comments 1 reaction 0 assignees View on GitHub
approved-in-principle area: primitives-and-literals
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

# Hexadecimal, octal and binary custom numeric literals

I propose we allow first-class support of colors.

```fs
module NumericLiteralR = ... // Implementation unchanged from before
let x : Color = 0xff00ff00R // Hexadecimal color literal!
```

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
1. Consistency - custom numeric literals should have the same support with built-in ones
2. Ease of use - enabling BigIntegers from their binary form
3. Support for more DSLs - e.g. Colors

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:
* [x] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [x] 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:
* [x] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.