typecase <expr> <type_arm> [<type_arm>]* [others ":" <body>] endwhere
<type_arm> -> when <type_designator> [ ( <idn> ) ] ":" <body>The expression expr is evaluated, and the actual type [tex2html_wrap2934] of the resulting object is then used to select a type_arm. The type_arms are considered in order, and the first one whose type designator denotes a supertype of type [tex2html_wrap2936] is selected: the object is assigned to the idn of that type_arm (if present), and the corresponding body is executed. Within this body the idn can be used to refer to the object with the type specified in the arm; the idn is defined only in this body. When execution of the body completes, control continues at the statement after the typecase. An others arm always matches, but provides no useful additional information about the object's type.
A legal typecase statement satisfies the following constraints:
The following example assumes "set" and "bag" are both subtypes of type "collection", and "stack" is a subtype of "bag":
x: collection ... typecase x when stack(y): ...% y is a stack in this arm when bag(z): ...% z is a bag in this arm others: ...% x must be used as a collection in this arm endThe others arm will be selected if "x"'s actual type is "set" (or some other "collection" type that is not a subtype of "stack" or "bag").