]>
In ugTypesDeclare we discussed how to declare a variable to restrict the kind of values that can be assigned to it. In this section we show how to declare a variable that refers to function objects.
A function is an object of type
{\sf Source Type}
where Source and Target can be any type. A common type
for Source is Tuple(, ...,
), usually written (, ...,
), to indicate a function of arguments.
If takes an Integer, a Float and another Integer, and returns a String, the declaration is written:
The types need not be written fully; using abbreviations, the above declaration is:
It is possible for a function to take no arguments. If takes no arguments but returns a Polynomial Integer, any of the following declarations is acceptable.
Functions can also be declared when they are being defined. The syntax for combined declaration/definition is:
functionName(: , ..., : ): functionReturnType
The following definition fragments show how this can be done for the functions and above.
A current restriction on function declarations is that they must involve fully specified types (that is, cannot include modes involving explicit or implicit ``?''). For more information on declaring things in general, see ugTypesDeclare .