3 ms·
if we want to squint and talk about sets and functions from sets to other sets... function voidy() : void { return; } echo json_encode(voidy()); /
by uryga 6y ago
if we want to squint and talk about sets and functions from sets to other sets...
function voidy() : void {
return;
}
echo json_encode(voidy()); // -> "null"
so i'd say that for most purposes
void ≡ {null}
a singleton set, more or less[1], sometimes called a "unit type". that's because a void function does return something, it's just entirely uninteresting :) that's different from an "empty" type
impossible ≡ {} // or ∅
with no values.
there are no values of type `impossible`, so `foo() : impossible` can never return anything at all, like this:
function foo() : impossible {
while(1){}
}
see mypy's `NoReturn`, Rust's `!`, Haskell's `Void`. it's used for giving a type to functions like `exit()`
[1] kind of, because it won't let you `return null` explicitly.