Chapter 5
Types and Classes
Overview
The Dylan type system is used to categorize all objects. In concert with generic functions, types determine the behavior of objects. When an object is passed as an argument to a generic function, the generic function looks at the type of the object to determine which method should be run.
Dylan supports several kinds of types, including classes, singletons, union types, and limited types.
- Classes are used to define the structure, inheritance, and initialization of all objects. An object can be an instance of any number of types, but will always be a direct instance of exactly one class.
- Singletons are used to indicate individual objects.
- Union types are used to indicate objects that are instances of one of a set of specified types.
- Limited types are used to indicate objects that are instances of another type and have additional constraints. There are several kinds of limited types.
All types are first class objects, and are general instances
of <type>
. Implementations may add additional kinds of types. The
language does not define any way for programmers to define new subclasses
of <type>
.