[Next] [Previous] [Up] [Top] [Contents] [Index]

5 Types and Classes

Union Types

Union types represent the union of the instances of two 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


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

Generated with Harlequin WebMaker