HOME

TheInfoList



OR:

In
type theory In mathematics, logic, and computer science, a type theory is the formal presentation of a specific type system, and in general type theory is the academic study of type systems. Some type theories serve as alternatives to set theory as a founda ...
, a theory within
mathematical logic Mathematical logic is the study of formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory. Research in mathematical logic commonly addresses the mathematical properties of forma ...
, 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 The up tack or falsum (⊥, \bot in LaTeX, U+22A5 in Unicode) is a constant symbol used to represent: * The truth value 'false', or a logical constant denoting a proposition in logic that is always false (often called "falsum" or "absurdum"). * T ...
(⊥) symbol. When the bottom type is empty, a function whose return type is bottom cannot return any value, not even the lone value of a
unit type In the area of mathematical logic and computer science known as type theory, a unit type is a type that allows only one value (and thus can hold no information). The carrier (underlying set) associated with a unit type can be any singleton set. ...
. In such a language, the bottom type may therefore be known as the zero or never type. In the
Curry–Howard correspondence In programming language theory and proof theory, the Curry–Howard correspondence (also known as the Curry–Howard isomorphism or equivalence, or the proofs-as-programs and propositions- or formulae-as-types interpretation) is the direct rela ...
, an empty type corresponds to falsity.


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 a type system is
sound In physics, sound is a vibration that propagates as an acoustic wave, through a transmission medium such as a gas, liquid or solid. In human physiology and psychology, sound is the ''reception'' of such waves and their ''perception'' by ...
, 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. If the bottom type is inhabited, its terms 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: # 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. # Bot is useful in typing the "leaf nodes" of polymorphic data structures. For example, List(Bot) is a good type for nil. # Bot is a natural type for the "
null pointer In computing, a null pointer or null reference is a value saved for indicating that the pointer or reference does not refer to a valid object. Programs routinely use null pointers to represent conditions such as the end of a list of unknown leng ...
" value (a pointer which does not point to any object) of languages like Java: in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
, the ''null type'' is the universal subtype of
reference type In computer programming, data types can be divided into two categories: value types (or by-value types) and reference types (or by-reference types). Value types are completely represented by their meaning, while reference types are references to ano ...
s. 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. # A type system including both Top and Bot seems to be a natural target for
type inference Type inference refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some branches of computer science and linguistic ...
, 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. In
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
, The undefined constant or terms created with the error constructor may be assigned any type. Attempting to evaluate such an expression causes the code to abort unrecoverably. In
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fr ...
the type NIL, contains no values and is a subtype of every 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 othing/code> is a subtype of List /code> 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 othing/code>. In
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO( ...
, the bottom type is called the never type and 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 Sri Lanka (, ; si, ශ්‍රී ලංකා, Śrī Laṅkā, translit-std=ISO (); ta, இலங்கை, Ilaṅkai, translit-std=ISO ()), formerly known as Ceylon and officially the Democratic Socialist Republic of Sri Lanka, is an ...
, 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
Julia Julia is usually a feminine given name. It is a Latinate feminine form of the name Julio and Julius. (For further details on etymology, see the Wiktionary entry "Julius".) The given name ''Julia'' had been in use throughout Late Antiquity (e.g ...
, the bottom type is Union. In
TypeScript TypeScript is a free and open source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. It is designed for the development of large app ...
, the bottom type is never. In
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
with
Closure Compiler Google Closure Tools is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps. Closure Compiler The Closure Compi ...
annotations, the bottom type is !Null (literally, a non-null member of the Null
unit type In the area of mathematical logic and computer science known as type theory, a unit type is a type that allows only one value (and thus can hold no information). The carrier (underlying set) associated with a unit type can be any singleton set. ...
). In PHP, the bottom type is never. In Python, the bottom type is typing.NoReturn (typing.Never since version 3.11). In Kotlin, the bottom type is Nothing. In D, the bottom type is noreturn In
Dart Dart or DART may refer to: * Dart, the equipment in the game of darts Arts, entertainment and media * Dart (comics), an Image Comics superhero * Dart, a character from ''G.I. Joe'' * Dart, a ''Thomas & Friends'' railway engine character * Da ...
, since version 2.12 with th
sound null safety update
the Never type was introduced as the bottom type. Before that, the bottom type used to be Null.


See also

*
Contradiction In traditional logic, a contradiction occurs when a proposition conflicts either with itself or established fact. It is often used as a tool to detect disingenuous beliefs and bias. Illustrating a general tendency in applied logic, Aristotle's ...
* Fail-stop *
NaN Nan or NAN may refer to: Places China * Nan County, Yiyang, Hunan, China * Nan Commandery, historical commandery in Hubei, China Thailand * Nan Province ** Nan, Thailand, the administrative capital of Nan Province * Nan River People Given name ...
* Top type *
Unit type In the area of mathematical logic and computer science known as type theory, a unit type is a type that allows only one value (and thus can hold no information). The carrier (underlying set) associated with a unit type can be any singleton set. ...


References


Further reading

* {{DEFAULTSORT:Bottom Type Data types Type theory