Type Specifications



next up previous contents index
Next: Parameterized Specifications Up: Specifications Previous: Stand-Alone Routine Specifications

Type Specifications

A type specification defines the interface of a type. It has the form

<type_interface> -> <idn> "=" type [<parms>] [<supertypes>] [<where>]
                [<interface_or_equate>]*
                end <idn>
where
        <interface_or_equate> -> <routine_interface> | <equate>
The initial idn is the identifier of the new type; this identifier will be used throughout the specification to refer to the new type. The final idn must be the same as the initial idn. The parms and where clauses are present only if the type is parameterized (9.3). In this section we consider only non-parameterized types.

The supertypes clause lists all supertypes of the new type except for "any", which is the supertype of all types and is never listed. The form is

        <supertypes> -> "<" <super_info> ["," <super_info>]*
        <super_info> -> <type_designator>  ["{" <renames> ["," <renames>]* "}"]
        <renames> -> <idn> for <idn>
The type_designator in a super_info clause identifies a type that is an immediate supertype of the new type. The optional renames clauses allow methods of that supertype to be renamed; the supertype method with the second name will be renamed with the first name in the subtype. For example,
stack = type < bag {push for put, pop for get}
states that "stack" is a subtype of "bag", except that the "bag" method named "put" will be renamed "push" within "stack" and the "bag" method named "get" will be renamed "pop" within "stack".

The remainder of the definition consists of equates and interfaces of the methods of objects of the type. Each method is defined by a routine_interface (9.1), and the type of the method is derived from this interface in the usual way. Each method must have a distinct name. Methods can be procedures or iterators; they can have parameters and can contain constraints (9.3). A routine_interface must be provided for a method when (1) there is no corresponding supertype method or (2) the subtype method has a different signature from that of the corresponding supertype method. The new names introduced by the renamings (if any) are used in these interfaces.

[usage1160]

The methods and their signatures determine the legality of the subtype declarations. A subtype must have all the methods of its supertype and the type of the subtype method must be a subtype of the type of the corresponding supertype method (3.4.1). Compilation of a type specification will fail if these conditions are not satisfied for every declared supertype.

[usage1170]

A type specification provides no way to create objects of the type ``from scratch.'' Instead, new objects are created by calls on stand-alone routines.

[usage1179]

Some examples of type specifications are given in Section 9.4.



next up previous contents index
Next: Parameterized Specifications Up: Specifications Previous: Stand-Alone Routine Specifications



theta-questions@lcs.mit.edu