Computer Science Applications
The bottom type is a 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 sometimes confused with the so-called "void type", which is actually a unit type, albeit one with no defined operations.
The bottom type is frequently used for the following purposes:
- To signal that a function or computation diverges; in other words, does not return a result to the caller. (This does not necessarily mean that the program fails to terminate; a subroutine may terminate without returning to its caller, or exit via some other means such as a continuation.)
- When coupled with the Curry-Howard interpretation of bottom as "falsity", this yields a computational interpretation of non-constructive logic in terms of control flow operators.
- As an indication of error; this usage primarily occurs in theoretical languages where distinguishing between errors is unimportant. Production programming languages typically use other methods, such as option types (including tagged pointers) or exception handling.
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.
- List 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 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 valuenull
. - 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.
Read more about this topic: Bottom Type
Famous quotes containing the words computer and/or science:
“The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital computer or the gears of a cycle transmission as he does at the top of a mountain or in the petals of a flower.”
—Robert M. Pirsig (b. 1928)
“When science is learned in love, and its powers are wielded by love, they will appear the supplements and continuations of the material creation.”
—Ralph Waldo Emerson (18031882)