DIP 1017--Add Bottom Type--Final Review
Q. Schroll
qs.il.paperinik at gmail.com
Thu Jan 17 02:32:48 UTC 2019
On Tuesday, 15 January 2019 at 16:23:57 UTC, Timon Gehr wrote:
> [...]
> It makes little sense to define a type "void" that has "no
> values" and then say "but as a special case, a function with
> return type void is a procedure instead", because you can just
> have a unit type. The whole "variables cannot be of type
> void"-nonsense is also nothing but annoying.
The void type is one of *three* type-theoretically different
types:
1. For any variables (local, parameter, field, ...), it *is* the
bottom type: You cannot have values of it.
2. For function returns, it is a unit type. In D, we have another
one: typeof(null). In fact, we could deprecate void returning
functions and use typeof(null) instead.
3. For pointer (i.e. void*) (and arrays (void[n]) and slices
(void[])), void is neither of the above. It's rather a top type
(or any, or unknown in TypeScript) which can hold any value. As
it is with Object, you cannot do anything (meaningful) with it
without explicit downcast.
This is not new -- it's inherited from C. If we get a bottom
type, void in the sense of 2. can be defined as void = bottom*.
More information about the Digitalmars-d
mailing list