2 ms·
But "void" is not an empty set, it is no set at all...
by choult 6y ago
But "void" is not an empty set, it is no set at all...
- uryga 6y agoif 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.