5 Types and Classes

- All types may be used as specializers for method parameters, bindings, and slots.
`instance?(`

tests type membership.*object, type)*`subtype?(`

tests type inclusion.*type1, type2)*`make(`

makes an instance. This operation is only supported if the type is instantiable.*type ...)*- Type objects are immutable.
- If two type objects are equivalent and are not classes, it is unspecified whether they are
`==`

.The following is an informal description of type relationships: The function

`subtype?`

defines a partial ordering of all types. Type*t*is a subtype of type*1**t*(i.e.*2*`subtype?(`

is true) if it is impossible to encounter an object that is an instance of*t**1, t2)**t*but not an instance of*1**t*. It follows that every type is a subtype of itself. Two types*2**t*and*1**t*are said to be*2***equivalent types**if`subtype?(`

and*t**1, t2)*`subtype?(`

are both true.*t**2, t1)**t*is said to be a*1***proper subtype**of*t*if*2**t*is a subtype of*1**t*and*2**t*is not a subtype of*2**t*.*1*`subtype?`

on classes is defined by inheritance. A class is a subtype of itself and of its general superclasses.`subtype?`

on singletons is defined by object type and identity. If*x*is an object and*t*is a type,`subtype?(singleton(`

will be true only if*x), t)*`instance?(`

is true.*x, t)*`subtype?`

rules for union types are given in "Union Types" on page 71.`subtype?`

rules for limited integer types are given in "Limited Integer Types" on page 72.`subtype?`

rules for limited collection types are given in "Limited Collection Types" on page 124.`<object>`

is the root of the type hierarchy. All objects are instances of`<object>`

, and all types are subtypes of`<object>`

.A number of operations on types are described in "Reflective Operations on Types" on page 329.

`limited(`*C,*

...`)`

is
The type *t 1* is a

Note that* t 1* being a subtype of

Base types and pseudosubtypes are used in the rules for sealing, described in Chapter 9, "Sealing."

- Two classes are disjoint if they have no common subclasses.
- A union type is disjoint from another type if both of the union type's component types are disjoint from that other type.
- A singleton type is disjoint from another type if the singleton's object is not an instance of that other type.
- A limited collection type is disjoint from a class if their base types are disjoint, or the class is a subclass of
`<collection>`

and its element type is definite and not equivalent to the limited collection type's element type, or the class is a subclass of`<collection>`

and its element type is indefinite and not a supertype of the limited collection type's element type. - A limited collection type is disjoint from a limited integer type. (Because the classes
`<collection>`

and`<integer>`

are disjoint.) - Two limited collection types are disjoint if their base types are disjoint, or their element types are not equivalent, or their sizes are not compatible. Two sizes are compatible if either is
`#f`

, or they are`=`

to each other, or one is a sequence of integers and the other is the product of those integers. - Two limited integer types are disjoint if the minimum value of one is greater than the maximum value for the other.
- A limited integer type is disjoint from a class if their base types are disjoint or the class is a subclass of
`<integer>`

whose range is disjoint from the limited integer type's range.

Dylan Reference Manual - 17 OCT 1995 [Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker