DIP 1017--Add Bottom Type--Final Review
Tim
tim.dlang at t-online.de
Thu Jan 17 17:17:45 UTC 2019
On Tuesday, 15 January 2019 at 08:59:07 UTC, Mike Parker wrote:
> DIP 1017, "Add Bottom Type", is now ready for Final Review.
> This is the last chance for community feedback before the DIP
> is handed off to Walter and Andrei for the Formal Assessment.
> Please read the procedures document for details on what is
> expected in this review stage:
>
> https://github.com/dlang/DIPs/blob/master/PROCEDURE.md#final-review
>
> The current revision of the DIP for this review is located here:
>
> https://github.com/dlang/DIPs/blob/4716033a8cbc2ee024bfad8942b2ff6b63521f63/DIPs/DIP1017.md
>
> In it you'll find a link to and summary of the previous review
> round. This round of review will continue until 11:59 pm ET on
> January 30 unless I call it off before then.
>
> Thanks in advance for your participation.
An advantage of the bottom type over an attribute is, that it is
part of the function type. A library allowing to set a custom
error handler could specify that the error handler must not
return:
alias ErrorHandler = TBottom function(string msg);
Here is another example for TBottom* == typeof(null): If a
library type allows custom user data with a template and you
don't need, you could specify TBottom.
struct LibraryType(UserData)
{
// ...
UserData* userData;
}
Since the compiler knows, that userData is always null, it could
eliminate dead code. Note that it would not be possible to
specify typeof(null) as the template parameter of LibraryType,
because then userData would be of type typeof(null)*.
The rules TBottom* == typeof(null) and TBottom[] == typeof([])
can also be generalized to custom types:
struct CustomArray(T)
{
T[] data;
void opAssign(T2)(CustomArray!T2 a2) if(is(T2:T))
{
data.length = a2.data.length;
foreach(i, x; a2.data)
data[i] = x;
}
}
auto literal(T...)(T params)
{
import std.traits;
static if(params.length == 0)
return CustomArray!TBottom();
else
return CustomArray!(CommonType!T)([params]);
}
unittest
{
CustomArray!int a = literal();
}
This could be simplified if CommonType!() == TBottom holds.
Note that this could also be implemented by replacing
CustomArray!TBottom with a special EmptyCustomArray type.
More information about the Digitalmars-d
mailing list