The Theta Type System



next up previous contents index
Next: Specifications Up: Overview of the Previous: Objects

The Theta Type System

Theta types are arranged in a hierarchy in which every type can have several supertypes. At the top of the hierarchy is the built-in type "any"; "any" is the supertype of all types. When a new type is defined, its definition indicates its supertypes. The Theta compiler ensures _conformance_: a subtype is guaranteed to have the methods of its supertypes, and these methods have compatible signatures. The type "any" has no methods, and therefore it imposes no constraints on its subtypes. A supertype's methods can be renamed so that the new names match what is needed in the subtype (9.2).

Theta provides strong, static type checking. Every variable has a declared type (4.5) that determines the type of object it can refer to. A variable is guaranteed to refer to an object whose actual type is a subtype of the variable's type (5.1). Every routine and method has a declared signature that determines the types of its arguments and results. The compiler ensures that all calls and assignments are consistent with this declared information. The conformance rule ensures that any call that is legal according to a variable's type will be legal for the actual object denoted by the variable. The exact type of a variable's object is not known at compile time, but more exact information can be determined by using the typecase statement (8.12), which tests an object's type at runtime.

Type hierarchy provides _subtype polymorphism_ and allows the definition of routines that are generic with respect to their arguments and results, and also of data structures that are generic with respect to their elements: in each case the actual objects can belong to a subtype of what is declared.



next up previous contents index
Next: Specifications Up: Overview of the Previous: Objects



theta-questions@lcs.mit.edu