fsharp / fsharp/fslang-suggestions

Extend custom numeric types to support floating point literals

Open
#445 3 comments 7 reactions 0 assignees View on GitHub
approved-in-principle area: primitives-and-literals needs rfc
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Currently you can define custom numeric types for integer values.
It would be nice to be able to handle floating point values too, e.g.

```fsharp
type complex =
| Complex of double * double

type imaginery =
| Imaginery of double
static member (+) (lhs:double,Imaginery(rhs)) = Complex(lhs,rhs)

module NumericLiteralI =
let FromZero () = Imaginery 0.0
let FromOne () = Imaginery 1.0
let FromInt32 (x) = Imaginery (double x)
let FromInt64 (x:int64) = Imaginery (double x)
let FromDouble (x:float) = Imaginery x // extension
let polar = 1.5 + 2.5I
```

**[Original UserVoice Submission](https://fslang.uservoice.com/forums/245727-f-language/suggestions/8140617)**

Contributor guide

No contributing guide indexed for this repository

Research direction

No implementation files, tests, or entry points are named. Start by reviewing issue #445, its F# numeric-literal example, and the linked original UserVoice submission. Done means the requested floating-point literal support has an agreed scope and is validated by appropriate compiler tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.