Next: , Up: Types   [Contents]


3.1 Builtin types

Certain special types are builtin, or are defined in the Mercury library:

Primitive types: char, int, float, string.

There is a special syntax for constants of type int, float, and string. (For char, the standard syntax suffices.)

Predicate types: pred, pred(T), pred(T1, T2), …
Function types: (func) = T, func(T1) = T,
func(T1, T2) = T, …

These higher-order function and predicate types are used to pass procedure addresses and closures to other predicates. See Higher-order.

Tuple types: {}, {T}, {T1, T2}, ….

A tuple type is equivalent to a discriminated union type (see Discriminated unions) with declaration

:- type {Arg1, Arg2, …, ArgN}
        ---> { {Arg1, Arg2, …, ArgN} }.
The universal type: univ.

The type univ is defined in the standard library module univ, along with the predicates type_to_univ/2 and univ_to_type/2. With those predicates, any type can be converted to the universal type and back again. The universal type is useful for situations where you need heterogeneous collections.

The “state-of-the-world” type: io.state.

The type io.state is defined in the standard library module io, and represents the state of the world. Predicates which perform I/O are passed the old state of the world and produce a new state of the world. In this way, we can give a declarative semantics to code that performs I/O.