DIP 1017--Add Bottom Type--Final Review

Neia Neutuladh neia at ikeran.org
Thu Jan 17 17:55:48 UTC 2019


On Thu, 17 Jan 2019 08:27:36 +0000, FeepingCreature wrote:
> On Wednesday, 16 January 2019 at 08:47:48 UTC, Johannes Loher wrote:
>> By the way, Kotlin does basically the same thing. Kotlin does not have
>> pointers, but it has optional types and the type `Nothing?` is a type
>> which can hold exactly one value: `null`. This also means that it is
>> basically a unit type. While it is not actually Kotlin's `Unit` type,
>> it could have been. Similarly, should we decide to go down that road
>> and add proper top, bottom and unit types, we could define
>>
>> ```
>> alias Tbottom = typeof(assert(0));
>> alias void = Tbottom*;
>> ```
> 
> That is amazing. I love it.

Unfortunately, it would mean void.sizeof is (void*).sizeof and 
incrementing a void* would increase it by four or eight instead of one, 
which would be a breaking change.

If D had distinct unit and raw-memory types, then that would be a valid 
way to define unit, but it would reserve four or eight bytes per variable 
instead of zero, which is suboptimal.


More information about the Digitalmars-d mailing list