Next: , Previous: , Up: Programs   [Contents][Index]


3.9.2 Type Declarations

All functions, relations, actions and TeleoR procedures have type declarations of the forms

fun Name(TypeTuple)->Type

rel Name(ModedTypeTuple)

act Name(ModedTypeTuple)

tel Name(TypeTuple)

As an example, below is the type declaration for the builtin append relation (with the same semantics as the standard Prolog append relation).

rel append(!list(T), !list(T), ?list(T)),
    append(?list(T), ?list(T), !list(T)),
    append(!list(??T), !list(??T), ?list(??T)),
    append(?list(??T), ?list(??T), !list(??T)),
    append(??list(T), ??list(T), ??list(T))

The first type of append says that, if the first two arguments of the call on append are ground lists of a given type, then the third argument will be a ground list of the same type on exit from the call.

The second type says that, if the third argument is a ground list of a given type, then the first and second arguments will be ground lists of the same type on exit from the call.

The third type of append says that, if the first two arguments are lists of a known length (i.e. do not have a variable tail) but possibly containing non-ground elements, then the third argument will have a known length on exit from the call but that variables occurring in any of the arguments need not be ground.

The fourth type is the "append driven backwards" version of the third type.

The fifth type is the most general allowing variable length lists in all arguments. In this situation, nothing can be said about the modes on exit from the call.

Note that when we say, for example, the first two arguments are of the same type we mean that the type inference system can find a suitable type as in the example interpreter query below.

| ?? append([1,2], [a,b], X).

X = [1, 2, a, b] : list(atom || nat)

Here, the suitable (minimal) type for T is the union of two types.

Dynamic relations are fact defined relations that can be updated by actions. They are declared as follows.

dyn NameTypeTuple

The declaration

dyn age_is(human,age)

is essentially the declaration

rel age_is(?human, ?age)

together with an implicit declaration that age_of is defined only by facts that are action updatable.

Dynamic relations are updated by primitive actions remember, forget etc.

Global variables are used to store either integer or number values and are declared as follows.

int Name := IntValue

or

num Name := NumValue

The declaration

int count := 0

is like a combination of the declaration

dyn count(int)

and the definition

count(0)

with the implicit restriction that the count dynamic relation is always defined with exactly one fact.

Global variables are updated using primitive actions :=, +:=, -:=.


Next: , Previous: , Up: Programs   [Contents][Index]