Basic Q types

Every well-formed expression has a precise type. The two basic types in Q are the following:

The types string, integer, real, and Boolean range over the corresponding primitive values; regexp ranges over regular expressions; and object ranges over instances of metaclasses.

Note: Object encompasses instances of all metaclasses. So instances of Package, Class, and so on, all have the type object.

In addition to the basic types, the Q language supports the following three forms of constructed types: tuples, collections, and functions.

Tuples

For any types α, β, … , ω, the expression α x β x … x ω denotes the type of a tuple with component types α, β, … , ω. For example, string x integer is the type of a pair with a string as the first component and an integer as the second component.

Collections

Collections are lists with possible duplicates. For any type α, α collection denotes the type of a collection of α. Some examples are object collection and string collection.

Functions

For any types α and β, α → β denotes a function that takes a parameter of type α and returns a value of type β. For example, stringinteger is the type of a function that takes a string and returns an integer.

Limitations

Although this scheme of type representation accommodates arbitrarily complex types, in practice there are limitations in the current implementation that restrict the complexity. Specifically, the current implementation supports the basic types, tuples of basic types, object collection, string collection, and functions that take and return any of these supported types, except for tuples for return types. There is also special support for the types (objectstring) x object collectionstring collection (which is the type of the built-in function map), (objectboolean) x object collectionobject collection (which is the type of the built-in function filter), and other such types for traverse and sort.

Complicated Type Examples

The following are some examples of more complicated types:

  • string x realboolean: A function that takes a tuple of two components—the first of type string and the second of type real—and returns a boolean.
  • (object → string) x object collection → string collection: A function that takes a function (of type object → string) and an object collection and returns a string collection.

Feedback