Union types represent the union of the instances of two or more other types. Union types are created with the function `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) ⇒ #f

The following rules govern `subtype?`

and `instance?`

for union types.

Given

*x*is an object.*s*and…s_{1}_{m}*t*are nonunion types.…t_{1}_{n}- The notation
`type-union*(`

stands for any arrangement of nested calls to*t*)…t_{1}_{n}`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}*,

`type-union(`

is type equivalent to *t_{1}*,

`type-union(`*t*_{2}, *t*_{1})

.`type-union(`

is type equivalent to *t_{1}*, type-union(

`type-union(type-union(`*t*_{1}, *t*_{2}), *t*_{3})

.`type-union(`

is type equivalent to *t_{1}*,

`subtype?(`*t*_{1}, *t*_{2})

.`instance?(`

will be true if and only if *x*, type-union*(*t_{1}…t_{n}*))

`instance?(`*x*, *t*)

is true for some `subtype?(type-union*(`

will be true if and only if *t_{1}…t_{n}*),

`subtype?(`*t*, *s*_{1})

is true for every `subtype?(`

will be true if and only if *s_{1}*, type-union*(

`subtype?(`*s*_{1}, *t*)

is true for some `subtype?(type-union*(`

will be true if and only if every *s_{1}…s_{m}*) type-union*(