Bottom Type--Type Theory

Meta jared771 at gmail.com
Thu Jan 17 02:59:09 UTC 2019


On Thursday, 17 January 2019 at 00:41:54 UTC, Jonathan Marler 
wrote:
> On Thursday, 17 January 2019 at 00:09:50 UTC, H. S. Teoh wrote:
>> On Wed, Jan 16, 2019 at 02:32:33PM -0800, Walter Bright via 
>> Digitalmars-d wrote: [...]
>>> [...]
>> [...]
>>
>> Actually, the *real* problem with `void` is that it has been 
>> overloaded to mean multiple, context-dependent things that are 
>> somewhat but not really the same, and aren't really compatible 
>> with each other.
>>
>> [...]
>
> A good summary of the issues with void. Maybe adding a bottom 
> type enables some new clever semantics, but I would venture to 
> guess that adding a real unit type would be even more helpful 
> than a bottom type. I've had cases where being able to use void 
> as a function parameter or a field would have made some of my 
> templates much cleaner. Maybe we should focus on making void a 
> real unit type before we try to add a bottom type?

D has a couple of different unit types which all behave 
differently:

typeof(null), its sole value being null. It also happens to be 
the bottom type for all objects, pointers and arrays.


void, which actually *does* have a single value - you just can't 
declare a variable with type void:

void main()
{
     auto v = new void[1];
     pragma(msg, typeof(v[0])); // Prints "void"
     import std.stdio;
     writeln(v[0]); // Error: template std.stdio.writeln cannot 
deduce function from argument types !()(void)
}

This may actually be a compiler bug/quirk; I'm not completely 
sure.


Any enum with only 1 element:

enum Unit
{
     val
}

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.


The empty struct:

struct Unit
{
}

Unit u;
writeln(u); // Prints Unit()


And probably more that I have missed.


More information about the Digitalmars-d mailing list