Bottom Type--Type Theory

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 17 10:39:18 UTC 2019


On Thu, Jan 17, 2019 at 02:59:09AM +0000, Meta via Digitalmars-d wrote:
[...]
> As an aside, the empty enum:
> 
> enum Empty
> {
> }
> 
> Is an uninhabited type similar to Bottom, but is not implicitly
> convertible to any other type, unlike Bottom.

Unfortunately, you get a compile error for this declaration.

But assuming it were allowed, then it would be possible to declare
multiple distinct empty enums that do not interconvert with each other,
which would mean that there is not one, but arbitrarily many bottom
types of this kind.


> The empty struct:
> 
> struct Unit
> {
> }
> 
> Unit u;
> writeln(u); // Prints Unit()

Oddly enough, Unit.sizeof == 1, as a hack for generating distinct
addresses when you declare multiple instances of Unit. One would have
expected .sizeof == 0 for a unit type (and NaN or an error if you
attempted to take .sizeof of an empty enum, if empty enums were
allowed).


T

-- 
It is widely believed that reinventing the wheel is a waste of time; but I disagree: without wheel reinventers, we would be still be stuck with wooden horse-cart wheels.


More information about the Digitalmars-d mailing list