HANDBOOK / GENTLE PRIMER / Describing Computations /

# Predicate Declarations

A predicate is declared by giving its signature and its rules. For example,

       'action' length (ColorList -> INT)

          'rule' length (list(Head, Tail) -> N+1) : length(Tail -> N)
          'rule' length (nil -> 0)

The signature of a predicate specifies its interface to the caller. It gives the name of the predicate and lists its parameter types. For example,

       'action' length (ColorList -> INT)

introduces a predicate `length` that has one input parameter of type `ColorList` and one output parameter of type `INT`.

Expressions and patterns in rule headings and invocations must be valid for the corresponding type.

In addition, a signature specifies the category of the predicate, which is `action` in the above example. The category of a predicate indicates how it is used and what its evaluation strategy is.

The general form is

- Category Name `(` InputTypes `->` OutputTypes `)`

Type names are separated by commas. If there are no output parameters, the arrow is omitted.

Parameter specifications may include identifiers for documentation:

       'action' length (L: ColorList -> N: INT)
       -- on exit N is the number of elements of L