encyclopegia.org

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. There is an isomorphism between any two such sets, so it is customary to talk about the unit type and ignore the details of its value. One may also regard the unit type as the type of 0-tuples, i.e. the product of no types. The unit type is the terminal object in the category of types and typed functions. It should not be confused with the zero or empty type, which allows no values and is the initial object in this category. Similarly, the Boolean is the type with two values. The unit type is implemented in most functional programming languages. The void type that is used in some imperative programming languages serves some of its functions, but because its carrier set is empty, it has some limitations (as detailed below).

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. There is an isomorphism between any two such sets, so it is customary to talk about the unit type and ignore the details of its value. One may also regard the unit type as the type of 0-tuples, i.e. the product of no types. The unit type is the terminal object in the category of types and typed functions. It should not be confused with the zero or empty type, which allows no values and is the initial object in this category. Similarly, the Boolean is the type with two values. The unit type is implemented in most functional programming languages. The void type that is used in some imperative programming languages serves some of its functions, but because its carrier set is empty, it has some limitations (as detailed below). ==In programming languages== Several computer programming languages provide a unit type to specify the result type of a function with the sole purpose of causing a side effect, and the argument type of a function that does not require arguments. In Haskell, Rust, and Elm, the unit type is called () and its only value is also () , reflecting the 0-tuple interpretation. In ML descendants (including OCaml, Standard ML, and F#), the type is called unit but the value is written as () . In Scala, the unit type is called Unit and its only value is written as () . In Common Lisp the type named is a unit type which has one value, namely the symbol . This should not be confused with the type, which is the bottom type. In Python, there is a type called NoneType which allows the single value of None . In Python's optional static type annotations, this type is represented as None . In Swift, the unit type is called Void or () and its only value is also () , reflecting the 0-tuple interpretation. In Java, the unit type is called Void and its only value is null . It cannot be instantiated. It is used in generics for denoting return types of void . In Go, the unit type is written struct{} and its value is struct{}{} . In PHP, the unit type is called null, which only value is NULL itself. In JavaScript, both Null (its only value is null ) and Undefined (its only value is undefined ) are built-in unit types. in Kotlin, Unit is a singleton with only one value: the Unit object. In Ruby, nil is the only instance of the NilClass class. In C++, the std::monostate unit type was added in C++17. Before that, it is possible to define a custom unit type using an empty struct such as struct Empty {} . In Dart, both Null and the empty record ( () , since Dart 3) have a single possible value, respectively, null and () . void f(void) {} void g(void) {} int main(void) { f(g()); // compile-time error here return 0; } This issue does not arise in most programming practice in C, because since the void type carries no information, it is useless to pass it anyway; but it may arise in generic programming, such as C++ templates, where void must be treated differently from other types. In C++ however, empty classes are allowed, so it is possible to implement a real unit type; the above example becomes compilable as: class UnitType {}; constexpr UnitType UNIT; UnitType f(UnitType) noexcept { return UNIT; } UnitType g(UnitType) noexcept { return UNIT; } int main() { f(g(UNIT)); return 0; } For brevity, UNIT is not implemented as a singleton; see singleton pattern for further explanation on singleton units. import java.util.concurrent.*; ExecutorService executorService = Executors.newFixedThreadPool(2); CompletableFuture future = CompletableFuture.runAsync(() -> { try { // Simulate some work System.out.println("Task started."); Thread.sleep(2000); // Simulate a 2-second task System.out.println("Task completed."); } catch (InterruptedException e) { System.err.println("Task was interrupted."); } }, executorService); Although the Void type can never have any instances, it does have one value, null (like all other reference types), so it acts as a unit type. In practice, any other non-instantiable type, e.g. Math , can also be used for this purpose, since they also have exactly one value, null . public static Void f(Void x) { return null; } public static Void g(Void x) { return null; } public static void main(String[] args) { f(g(null)); } typeof(null) returnThatSpecialThing() { return null; } void writeTypeOfNull() { writeln(typeof(null)); // prints: void } null is the only value that typeof(null) , a unit type, can have. ==See also== Any type Bottom type Singleton pattern (where a particular class has only one instance, but narrowly typed non-nullable references to it are usually not held by other classes) Undefined Void type ==Notes== ==References==

References

No reference rows published for this article.

Cite this article

MLA

"unit type." encyclopegia.org, 2025, https://encyclopegia.org/wiki/unit-type. Accessed 24 November 2026.

Chicago

"unit type." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/unit-type.

APA

encyclopegia.org. (2025). unit type. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/unit-type

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

James Fitz-Allen Mitchell

stub · references available

Günthardt

stub · references available

Ousmane N'Diaye

stub · references available

Battle of Elasa

stub · references available

integral nationalism

stub · references available

Forbidden

stub · references available
CC BY-SA 4.0 · tier1-factual · https://en.wikipedia.org/w/index.php?oldid=1326270108 · 0.55 · snapshot unit-type-152017-e8a1393b2aefb1cb · QID Q1307872

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.