Bottom type

In type theory, a theory within mathematical logic, the bottom type of a type system is the type that is a subtype of all other types.

Where such a type exists, it is often represented with the up tack (⊥) symbol.

Relation with the empty type

When the bottom type is uninhabited, a function whose return type is bottom cannot return any value, not even the lone value of a unit type. In such a language, the bottom type may therefore be known as the zero, never or empty type which, in the Curry–Howard correspondence, corresponds to falsity.

However, when the bottom type is inhabited, it is then different from the empty type.

If a type system is sound, the bottom type is uninhabited and a term of bottom type represents a logical contradiction. In such systems, typically no distinction is drawn between the bottom type and the empty type, and the terms may be used interchangeably.

Computer science applications

In subtyping systems, the bottom type is a subtype of all types. It is dual to the top type, which spans all possible values in a system.

If the bottom type is inhabited, its term(s) typically correspond to error conditions such as undefined behavior, infinite recursion, or unrecoverable errors.

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(Bot) is a good type for nil.
  3. Bot is a natural type for the "null pointer" value (a pointer which does not point to any object) 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 is not a bottom type as described above, it is not a subtype of int and other primitive types.
  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 denote the bottom type. There are a few notable exceptions.

See also

References

  1. 1 2 3 Pierce, Benjamin C. (1997). "Bounded Quantification with Bottom". Indiana University CSCI Technical Report (492): 1.
  2. ↑ "Section 4.1: The Kinds of Types and Values". Java Language Specification (3rd ed.).
  3. ↑ "Data.Void". Hackage. Retrieved 2023-09-20.
  4. ↑ "Type NIL". Common Lisp HyperSpec. Retrieved 25 October 2022.
  5. ↑ "Primitive Type never". The Rust Standard Library Documentation. Retrieved 2020-09-24.
  6. ↑ cppreference.com. "C++ attribute noreturn (since C++11)". cppreference.com. cppreference.com. Retrieved 14 June 2026.
  7. ↑ "Chapter 3. Type system — 3.2.5. The bottom type". The Ceylon Language. Red Hat, Inc. Retrieved 2017-02-19.
  8. ↑ "Essentials - The Julia Language", The Julia Programming Language Documentation, retrieved 2021-08-13
  9. ↑ The never type, TypeScript 2.0 release notes, Microsoft, 2016-10-06, retrieved 2019-11-01
  10. ↑ The never type, TypeScript 2.0 release notes, source code, Microsoft, 2016-10-06, retrieved 2019-11-01
  11. ↑ "typing — Support for type hints — Python 3.12.0a0 documentation". docs.python.org. Retrieved 2024-03-02.
  12. ↑ typing.NoReturn, typing — Support for type hints, Python documentation, Python Software Foundation, retrieved 2024-03-02
  13. ↑ Nothing, retrieved 2020-05-15
  14. ↑ "Types - D Programming Language". dlang.org. Retrieved 2022-10-20.
  15. ↑ Understanding null safety - top and bottom, retrieved 2022-04-13
  16. ↑ Understanding null safety - never for unreachable code, retrieved 2022-04-13

Further reading