Nothing type/value aka Unit
Jonathan Levi
catanscout at gmail.com
Fri Feb 8 13:32:22 UTC 2019
In D what would be the most appropriate type for a value that
specifically does not carry a value?
I am working on porting Sodium, a simple FRP library, to D (or
making one like it). In FRP, events (aka event occurrences) must
contain 1 and only 1 value. So when there is no appropriate
value, they make its value what they call a Unit.
For the java version of Sodium they define the unit like `enum
Unit { UNIT }`. In Haskell when this thing is needed `()` is
used (an empty tuple).
Is there a more appropriate way to do this in D? Perhaps in
Phobos?
What makes more sense then `enum Unit { unit }` to me is `struct
Unit {}; enum Unit unit;`.
More information about the Digitalmars-d
mailing list