Subtypes

To say that S is a subtype of T means that any term of type S can appear in an expression where a term of type T is expected. Including subtypes in the type system allows, for example, putting an Integer in an expression that is defined to accept a Real.

In the Sym application, subtype relationships between types are declared explicitly in the Subtypes function in the Sym namespace. The Subtypes function has to contain clauses of the form "A subtype B".

The subtypes defined by the Subtypes function have to form a directed acyclic graph. The subtypes validator is run at the beginning of each build to make sure that there are no cycles in the list of subtypes returned by the Subtypes function (a build is also run when a file is opened). If any cycles (for example, A subtype B, B subtype C, C subtype A) are found, some of the clauses will be disabled to eliminate the cycles and an error message will be shown in the Error Manager.

The subtype validator will also test for clauses of the form "A subtype A". This clause is disabled and a warning message is generated because "A subtype A" is true by definition.

The type inferencing process refers to the Subtypes function when it needs to determine if one type is a subtype of another.

The list of type relationships provided by the Subtypes function can be extended in newly created libraries and in individual documents if desired.