Bottom type


In type theory, a theory within mathematical logic, the bottom type is the type that has no values. It is also called the zero or empty type, and is sometimes denoted with the up tack symbol.
A function whose return type is bottom cannot return any value, not even the zero size unit type. Therefore a function whose return type is the bottom type cannot return. In the Curry–Howard correspondence, the bottom type corresponds to falsity.

Computer science applications

In subtyping systems, the bottom type is the subtype of all types. It is used to represent the return type of a function that does not return a value: for instance, one which loops forever, signals an exception, or exits.
Because the bottom type is used to indicate the lack of a normal return, it typically has no values. It contrasts with the top type, which spans all possible values in a system, and a unit type, which has exactly one value.
The bottom type is frequently used for the following purposes:
In Bounded Quantification with Bottom, Pierce says that "Bot" has many uses:
  1. In a language with exceptions, a natural type for the raise construct is raise ∈ exception -> Bot, and similarly for other control structures. Intuitively, Bot here is the type of computations that do not return an answer.
  2. Bot is useful in typing the "leaf nodes" of polymorphic data structures. For example, List is a good type for nil.
  3. Bot is a natural type for the "null pointer" value of languages like Java: in Java, the null type is the universal subtype of reference types. null is the only value of the null type; and it can be cast to any reference type. However, the null type does not satisfy all the properties of a bottom type as described above, because bottom types cannot have any possible values, and the null type has the value null.
  4. A type system including both Top and Bot seems to be a natural target for type inference, allowing the constraints on an omitted type parameter to be captured by a pair of bounds: we write S<:X<:T to mean "the value of X must lie somewhere between S and T." In such a scheme, a completely unconstrained parameter is bounded below by Bot and above by Top.

    In programming languages

Most commonly used languages don't have a way to explicitly denote the empty type. There are a few notable exceptions.
Since Haskell2010, Haskell supports empty data types. Thus, it allows the definition data Empty. The type Empty is not quite empty, as it contains non-terminating programs and the undefined constant. The undefined constant is often used when you want something to have the empty type, because undefined matches any type, and attempting to evaluate undefined will cause the program to abort, therefore it never returns an answer.
In Common Lisp the symbol NIL, amongst its other uses, is also the name of a type that has no values. It is the complement of T which is the top type. The type named NIL is sometimes confused with the type named NULL, which has one value, namely the symbol NIL itself.
In Scala, the bottom type is denoted as Nothing. Besides its use for functions that just throw exceptions or otherwise don't return normally, it's also used for covariant parameterized types. For example, Scala's List is a covariant type constructor, so List is a subtype of List for all types A. So Scala's Nil, the object for marking the end of a list of any type, belongs to the type List.
In Rust, the bottom type is denoted by !. It is present in the type signature of functions guaranteed to never return, for example by calling panic! or looping forever. It is also the type of certain control-flow keywords, such as break and return, which do not produce a value but are nonetheless usable as expressions.
In Ceylon, the bottom type is Nothing. It is comparable to Nothing in Scala and represents the intersection of all other types as well as an empty set.
In TypeScript, the bottom type is never.
In Python, the bottom type is typing.NoReturn.
In Kotlin, the bottom type is Nothing.