next up previous
Next: Type Conversions Up: Compiler Theory: Type Checking Previous: Specification of a Simple Type

Type Equivalence


TYPE CHECKING RULES usually have the form

if two type expressions are equivalent
then return a given type
else return type_error


KEY IDEAS. The central issue is then that we have to define when two given type expressions are equivalent.


STRUCTURAL EQUIVALENCE. If type expressions are built from basic types and constructors (without type names, that is in our example, when using products instead of records), structural equivalence of types can be decided easily.

RECURSIVE TYPES. In PASCAL a linked list is usually defined as follows.

type link = ^ cell;
     cell = record
               info: type;
               next: link;
            end;
The corresponding type graph has a cycle. So to decide structural equivalence of two types represented by graphs PASCAL compilers put a mark on each visited node (in order not to visit a node twice). In C, a linked list is usually defined as follows.
struct cell {
    int info;
    struct cell *next;
};
To avoid cyclic graphs, C compilers


next up previous
Next: Type Conversions Up: Compiler Theory: Type Checking Previous: Specification of a Simple Type
Marc Moreno Maza
2004-12-02