5 Types and Classes

`type-union`

. They are not classes.
Union types are useful as slot specializers, and describe the return types of many common functions. For example, the return type of the collection method on `size`

could be expressed as `type-union(<integer>, singleton(#f))`

.

define constant <green-thing> = type-union(<frog>, <broccoli>); define constant kermit = make(<frog>); define method red? (x :: <green-thing>) #f end method; red?(kermit) Þ #fThe following rules govern

`subtype?`

and `instance?`

for union types.Given

*x*is an object.*s*and*1...sm**t*are non-union types.*1...tn*- The notation
`type-union*(`

stands for any arrangement of nested calls to*t**1...tn)*`type-union`

, where none of the arguments is a subtype of any other, and none of the arguments forms an exhaustive partition of any other type.Then

`type-union(`

is type equivalent to*t**1, t1)**t**1*`type-union(`

is type equivalent to*t**1, t2)*`type-union(`

*t**2, t1)*`type-union(`

is type equivalent to*t**1, type-union(t2, t3))*`type-union(type-union(`

*t**1, t2), t3)*`type-union(`

is type equivalent to*t**1, t2)**t*when*2*`subtype?(`

*t**1, t2)*`instance?(x, type-union*(`

will be true if and only if*t**1...tn))*`instance?(`

is true for some*x, t)**t*in*t*.*1...tn*`subtype?(type-union*(`

will be true if and only if*t**1...tn), s1)*`subtype?(`

is true for every*t, s**1)**t*in*t*.*1...tn*`subtype?(`

will be true if and only if*s**1, type-union*(t1...tn))*`subtype?(`

is true for some*s**1, t)**t*in*t*.*1...tn*`subtype?(type-union*(`

will be true if and only if every*s**1...sm) type-union*(t1...tn))**s*in*s*is a subtype of some*1...sm**t*in*t*.*1...tn*

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

Generated with Harlequin WebMaker