| TypeDecl | |||
| ::= | TypeNameDecl | ||
| | | DataTypeDecl | ||
| | | EnumTypeDecl | ||
| | | TagTypeDecl | ||
| | | ObjectTypeDecl | ||
| TypeNameDecl | |||
| ::= | type TypeId TypeParamsopt = Type | ||
| ObjectTypeDecl | |||
| ::= | objtype TypeId TypeParamsopt ObjectMembers | ||
| | | objtype TypeId TypeParamsopt = NamedType | ||
| ObjectMembers | |||
| ::= | { ObjectMember* } | ||
| ObjectMember | |||
| ::= | extends NamedType | ||
| | | field Label : ExtendedType | ||
| | | method Label : TypeScheme | ||
| DataTypeDecl | |||
| ::= | datatype TypeId TypeParamsopt DataTypeDef | ||
| | | datatype TypeId TypeParamsopt = NamedType | ||
| DataTypeDef | |||
| ::= | { DataConDef (, DataConDef)* } | ||
| DataConDef | |||
| ::= | DataCon (of Types)opt | ||
| EnumTypeDecl | |||
| ::= | enumtype TypeId EnumTypeDef | ||
| | | enumtype TypeId = Pathopt TypeId | ||
| EnumTypeDef | |||
| ::= | { DataCon (, DataCon)* } | ||
enumtype T { C1, ..., Cn }the following operations are defined:
| Operation | Type | Description | |
| T.toInt | T -> Int | Convert to integer; C1 maps to 0 and Cn maps to n-1. | |
| T.fromInt | Int -> T | Convert an integer to T; 0 maps to C1 and n-1 maps to Cn. Out of range values cause the exception Range to be raised. | |
| T.first | T | The first element of the enumeration (i.e., C1). | |
| T.last | T | The last element of the enumeration (i.e., Cn). | |
| T.succ | T -> T | Returns the successor of its argument; raises the exception Range on Cn. | |
| T.pred | T -> T | Returns the predecessor of its argument; raises the exception Range on C0. | |
| T.compare | T -> Order | Compares the order of two elements. | |
| TagTypeDecl | |||
| ::= | tagtype TypeId TypeParamsopt (of Types)opt (extends NamedType)opt | ||
| | | tagtype TypeId TypeParamsopt = NamedType | ||
tagtype T of (t1, ..., tn)defines a root tagtype T. The name T also serves as a data constructor. A tagtype declaration of the form
tagtype S of (s1, ..., sm) extends Tdefines a tagtype S that is a subtype of the type T. In order that the declaration of S be valid, we require that m ³ n and that for 1 £ i £ n we have G |- si <: ti.