Documentation menu
Language

Universes

Types as values, the hierarchy of universes, universe levels and the definitions that abstract over them, Typeω, and the impredicative bottom universe.

Find a section3 sections

Types are values, and they have types too. Type, short for Type 0, is the type of ordinary types. Type has type Type 1, also written Kind, and Type 1 has type Type 2, also written Sort:

Type
{ natural = Natural, type = Type, kind = Kind, sort = Sort }
Your result
Complete example · with imports

Type

{ kind : Type 2, natural : Type, sort : Type 3, type : Type 1 }

Levels

A definition works in every universe when it abstracts over a level:

Type
let id : forall {l : Level} {a : Type l} -> a -> a = \x -> x
in  { number = id 1, type = id Natural, kind = id Type }
Your result
Complete example · with imports

Type

{ kind : Type 1, number : Natural, type : Type }

The whole standard library is written so (universe polymorphism in the library).

A level is a number from 0 to 1000, a variable of type Level, Level/suc l, Level/max a b or Level/imax a b. A level written as a number costs time and memory in proportion to its value, hence the bound:

Rejected
Type 1001
Your result
Complete example · with imports

Error E0026

error[E0026]: this universe level is too large
  ┌─ example.omg:1:6
  │
1 │ Type 1001
  │      ^^^^ a universe level written as a number can be at most 1000
  │
  = a level is represented by counting up from `0`, so it costs time and memory in proportion to its value
  = help: a definition that should work in every universe can abstract over the level: `forall {l : Level} -> ...`

Levels are not data. They can only be abstracted over and passed to Type: no record, list or function result holds one.

Rejected
{ level = Level }
Your result
Complete example · with imports

Error E0016

error[E0016]: universe levels are not data
  ┌─ example.omg:1:11
  │
1 │ { level = Level }
  │           ^^^^^ a record field cannot be the type `Level`
  │
  = a `Level` can only be abstracted over (`forall (l : Level) -> ...`) and passed to `Type`

Typeω

A type that quantifies over levels lives in Typeω, which is not itself a term. A definition can name such a type, and a record can hold values whose types quantify over levels:

Type
let Polymorphic : Typeω = forall {l : Level} {a : Type l} -> a -> a
let id : Polymorphic = \x -> x
in  { number = id 1, type = id Natural }
Your result
Complete example · with imports

Type

{ number : Natural, type : Type }

No record, pair or list holds a type of Typeω, and no function returns one:

Rejected
let Polymorphic : Typeω = forall {l : Level} {a : Type l} -> a -> a
in  { Polymorphic }
Your result
Complete example · with imports

Error E0025

error[E0025]: types that live in `Typeω` are not data
  ┌─ example.omg:2:7
  │
2 │ in  { Polymorphic }
  │       ^^^^^^^^^^^ a record field cannot be a type that lives in `Typeω`
  │
  = `Typeω`, the sort of the types that quantify over universe levels, is not itself a term: what contained such a type, or returned one, would have a type that mentions `Typeω`
  = help: give the type a name with `let` instead: a definition can be a type that lives in `Typeω`

The impredicative bottom universe

Type 0 is impredicative: a function type that quantifies over all the types of Type is itself a type of Type. Above it, a function type lives in the larger of the universes of its domain and of its codomain:

Type
{ small = forall (a : Type) -> a -> a
, large = forall (a : Type 1) -> a -> a
}
Your result
Complete example · with imports

Type

{ large : Type 2, small : Type }

There is no cumulativity: a type of Type is not also a type of Type 1. Lifted types shows how a record type is lifted to a higher universe.