You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type Planets =
| MERCURY of (3.303e+23, 2.4397e6)
| VENUS of (4.869e+24, 6.0518e6)
| EARTH of (5.976e+24, 6.37814e6)
| MARS of (6.421e+23, 3.3972e6)
| JUPITER of (1.9e+27, 7.1492e7)
| SATURN of (5.688e+26, 6.0268e7)
| URANUS of (8.686e+25, 2.5559e7)
| NEPTUNE of (1.024e+26, 2.4746e7)
Using an anonymous record to associate constant values (if we get anonymous records in F#):
type Planets =
| MERCURY of {Mass=3.303e+23; Radius=2.4397e6)
| VENUS of {Mass=4.869e+24; Radius=6.0518e6),
| EARTH of {Mass=5.976e+24; Radius=6.37814e6),
| MARS of {Mass=6.421e+23; Radius=3.3972e6),
| JUPITER of {Mass=1.9e+27; Radius=7.1492e7),
| SATURN of {Mass=5.688e+26; Radius=6.0268e7),
| URANUS of {Mass=8.686e+25; Radius=2.5559e7),
| NEPTUNE of {Mass=1.024e+26; Radius=2.4746e7);
The disadvantages of making this adjustment to F# are apart form the work involved, I honestly don't know :)
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
Related suggestions: (put links to reated suggestions here)
Affadavit (must be submitted)
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
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 would be willing to help implement and/or test this
I or my company would be willing to help crowdfund F# Software Foundation members to work on this
The text was updated successfully, but these errors were encountered:
Allow constant values on Discriminated Unions
I propose we allow discriminated unions to have constant values defined on the type
The existing way of approaching this problem in F# is creating a pattern match function to associate values with DU
Pros and Cons
The advantages of making this adjustment to F# are simplicity in design, specially in programs that make heavy usage of constant data.
Example using the famous Java planets sample (http://snipplr.com/view/42422/the-planet-enum-example/):
Using a tuple to associate constant values:
type Planets =
| MERCURY of (3.303e+23, 2.4397e6)
| VENUS of (4.869e+24, 6.0518e6)
| EARTH of (5.976e+24, 6.37814e6)
| MARS of (6.421e+23, 3.3972e6)
| JUPITER of (1.9e+27, 7.1492e7)
| SATURN of (5.688e+26, 6.0268e7)
| URANUS of (8.686e+25, 2.5559e7)
| NEPTUNE of (1.024e+26, 2.4746e7)
Using an anonymous record to associate constant values (if we get anonymous records in F#):
type Planets =
| MERCURY of {Mass=3.303e+23; Radius=2.4397e6)
| VENUS of {Mass=4.869e+24; Radius=6.0518e6),
| EARTH of {Mass=5.976e+24; Radius=6.37814e6),
| MARS of {Mass=6.421e+23; Radius=3.3972e6),
| JUPITER of {Mass=1.9e+27; Radius=7.1492e7),
| SATURN of {Mass=5.688e+26; Radius=6.0268e7),
| URANUS of {Mass=8.686e+25; Radius=2.5559e7),
| NEPTUNE of {Mass=1.024e+26; Radius=2.4746e7);
The disadvantages of making this adjustment to F# are apart form the work involved, I honestly don't know :)
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
Related suggestions: (put links to reated suggestions here)
Affadavit (must be submitted)
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: