Hacker News new | past | comments | ask | show | jobs | submit login

But "void" is not an empty set, it is no set at all...



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.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: