Programming Search⌘K

Forms of types

The forms that types take beyond the primitive types: composite types, function types, and the special types unit, bottom and top.

Concepts

  • Composite type

    A composite type builds a value from values of other types: arrays, records, tuples, maps, unions, functions and pointers. A type constructor such as list[int] makes it.

    intro
  • Function type

    A function type is the type of a function value: its parameter types and its result type, as in int -> int. It lets a program pass, return and store functions.

    core
  • Unit type

    The unit type has exactly one value, so a value of it carries no information. A function that runs only for its side effects returns it, as () in Rust or None in Python.

    core
  • Value types and reference types

    A variable of a value type holds the value, so assignment copies it. A variable of a reference type holds a reference, so assignment shares one object between two names.

    core
  • Bottom type

    The bottom type has no values and is a subtype of every type. It is the result type of code that never returns, such as a throw, a panic or an endless loop.

    advanced
  • Literal and singleton types

    A literal type, or singleton type, has one value, such as "left" or 42. A union of literal types lists the values that a variable may hold, and the checker rejects any other value.

    advanced
  • Opaque type

    An opaque type hides its representation from the code that uses it, so that code can work with the values only through the operations that the defining module gives.

    advanced
  • Top type

    The top type is a supertype of every type, so a variable of it can hold any value. Java and C# call it Object, Python object, Kotlin Any? and TypeScript unknown.

    advanced