3 ms·
No. First, null is generally a value, not a type. Second, think of bottom types as "does not return". Taking C as an example: C doesn't have a bottom type, o
by Ao7bei3s 7y ago
No.
First, null is generally a value, not a type.
Second, think of bottom types as "does not return".
Taking C as an example: C doesn't have a bottom type, only void which is a unit type (it has a single value, which is anonymous in C). However you can tell the compiler that you _actually_ meant the bottom type:
void panic() __attribute__((noreturn)) {
while(1) {
}
__builtin_unreachable();
}
Scala is also interesting, in that it supports all three (Null, Unit, Nothing).
- afiori 7y agoBottom should rather be the empty type and one consequence of that is that is you happen to build a x of type bottom then x sort of belongs to every type
- Ao7bei3s 7y agoThat's the formal definition, and an interesting corollary with interesting consequences (from a typing perspective, a function of any return type can always opt to halt instead of returning. note that in a lazily evaluated language like Haskell the caller can still continue, as long as it does not evaluate the result). But I didn't go with that because it doesn't answer the question (is null the bottom type? no.), and in the context of return types (the main use case, though not the only) it's equivalent to what I said (no possible return value -> cannot return).