The unit type, the canonical type with one element, named unit
or ()
.
In other words, it describes only a single value, which consists of said constructor applied
to no arguments whatsoever.
The Unit
type is similar to void
in languages derived from C.
Unit
is actually defined as PUnit.{1}
where PUnit
is the universe
polymorphic version. The Unit
should be preferred over PUnit
where possible to avoid
unnecessary universe parameters.
In functional programming, Unit
is the return type of things that "return
nothing", since a type with one element conveys no additional information.
When programming with monads, the type m Unit
represents an action that has
some side effects but does not return a value, while m α
would be an action
that has side effects and returns a value of type α
.