Declaring Types

Programmers may declare new named data structures with the following procedure:

:- foreign_type
    Type_name = Type,
    Type_name = Type.

where Type_name is an atom, and Type defines either an atomic or compound type, or is a previously-defined type name.

In Prolog, atomic types are represented by the natural atomic term (integer, float, or atom). Compound structures are represented by terms whose functor is the name of the type, and whose only argument is the address of the data. So a term foo(123456) represents the thing of type foo that exists at machine address 123456. And a term integer(123456) represents the integer that lives in memeory at address 123456, not the number 123456.

For types that are not named, a type name is generated using the names of associated types and the dollar sign character (‘$’), and possibly a number. Therefore, users should not use ‘$’ in their type names.

Send feedback on this subject.