Nothing type/value aka Unit

JN 666total at wp.pl
Fri Feb 8 14:41:16 UTC 2019


On Friday, 8 February 2019 at 13:32:22 UTC, Jonathan Levi wrote:
> 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;`.

how about Nullable!Event?


More information about the Digitalmars-d mailing list