Types
The terms that make up the language part of AIDDL have no link to any concrete AI problem by themselves. These links are established by defining types within the language. In this way we can establish different fragments of AIDDL that express well known problems.
AIDDL types are expressed within AIDDL through the expressions detailed below. We first go over the basic builing blocks and then discuss how constraints can be attached to types, as well as how generic types can be defined in AIDDL.
Basic Types
Basic types do not need to be defined and can always be used with the references listed in the table below. Shorter names can be used with the help of namespaces. Custom types often utilize basic types.
Name | Reference | Description | Examples |
|---|---|---|---|
Term |
| Every AIDDL expression is a term. | see below |
Symbolic |
| Non-numerical constants. |
|
Boolean |
| Boolean constants |
|
Variable |
| Named variables beginning with |
|
String |
| Any string of characters in quotes. |
|
Numerical |
| Different types of numerical values. | see below |
Integer |
| Positive or negative integers. |
|
Rational |
| Positive or negative rational numbers. |
|
Real |
| Positive or negative real numbers. |
|
Infinity |
| Positive or negative infinity. |
|
NaN |
| Not a Number |
|
Collection |
| Collections of terms. | see below |
Set |
| A set of terms. Cannot be matched to other terms. |
|
List |
| A list of terms. |
|
Tuple |
| A tuple of terms. Unlike lists, we assume tuples will not be extended. |
|
Reference |
| A reference to an entry in a specific module. |
|
Function Reference |
| Reference to a function. Allows using functions as data. |
|
| |||
Key Value Pair |
| A key and a value term. The key must not be a Key-value pair itself. |
|
Type Expressions
Types can be specified in AIDDL via #type entries that specify a name and a type definition. Assuming a symbolic name for the type, the new types URI will be its module URI concatenated with the type name. Defining a type will create a membership function with the type's URI. This function can be used to test if a term satisfies a type.
The following example defines a new type called org.aiddl.my-module.new-type which is an AIDDL set.
This example can be seen as simply renaming the AIDDL set type. The ^ signals that the following is a function reference. This would allow us to write an entry
using a function reference to the name of the type in the type slot of the entry.
Any basic AIDDL type can be used in a type definition, but in most cases we would like to be more precise. For this, we can employ a combination of type specifiers. In the following examples, we assume the basic namespace to make the definitions more compact.
The following sections go over a variety of commonly used type constructs.
Enumerations
Enumeration types define a type through a list of possible terms.
Numerical Ranges
Range types specify a numerical range.
Typed Collections
Collection types limit collections, lists or sets to elements of a specific type. This is the first example of a type that includes other types.
Whenever a type is expected, we can define it directly instead of using a named type.
If we use a defined type, we can use the full URI, a self reference (if defined in the current module) or an entry reference. The following three definitions are identical in the current module:
This works because after a ^ all references are translated to the full symbolic URI. Similar types can be defined with type.list for typed lists and type.col for typed lists or sets.
Unions and Intersections
We can also specify type unions and intersections. A union of two or more types creates a type that include the members of all the given types. The following type will consist of all terms that are variables or symbols:
An intersection of two or more given types creates a type whose members belong to every individual type. The following example creates an intersection between to enum types. The final type will consist only of the symbols b and c.
Typed Key-value Pairs
A typed key-value pair allow us to restrict the type of the key and value of a key-value pair. The following example creates a type that includes all key-value pairs whose keys are symbols and whose values are numerical:
Signed Tuples
A signed tuple gives a list of types for the corresponding fields in a tuple. The following type contains all tuples of length three containing a numerical term in the first and third field, and a symbolic term in the last field:
Signed tuples also allow to specify minimum length, maximum length and how the last elements are repeated. The following type constains all tuples with minimum length five and whose fields alternate between symbolic and numerical starting at the fourth field.
Dictionary
Dictionaries allow to specify types for tuples or collections that contain types behind certain keys. The following type includes all tuples or collections that have a key from and a key to pointing to a symbol and a key weight pointing to a numerical:
Matrix
Matrix types can be used to define lists/tuples of lists/tuples. We can define types by row, column, or for each cell and restrict the size. The following example defines a type for a 3-by-3 matrix of symbolic terms:
The next example instead specifies types for the rows in the matrix. Each row consists of a symbolic, a variable, and a numerical term in this order:
The final example applies the same idea to the colums of the matrix:
If m and row-types are provided we assume m to equal the number of row types (and the same for n and col-types). Otherwise the type is empty.
Constraints
Any type definition can be provided with a reference to a Boolean function that will be treated as a constraint on a term. The following type contains all tuples of symbols and of length two whose elements are not equal.
Generic Types
If a type is determined in terms of one or more other types, we can define a generic type by using a tuple with the name of the type constructorfollowed by variables to represent generic types used elsewhere in the type definition.
Suppose we want to define a generic type pair of tuples of length two without deciding its field types. The following accomplishes this:
Rather than a type the above should be seen as a type constructor. Internally, a function org.aiddl.my-module.pair will be generated that takes two arguments and returns a type function. As a result, we can use the following to create a set of all pairs of symbolic terms.
When
is evaluated, it will be replaced by
which is an actual type that can be used by the type checker. The name above may change depending on the implementation or the order in which types are constructed from a generic type.