Professional Documents
Culture Documents
What Is A Type?: Topics To Be Covered
What Is A Type?: Topics To Be Covered
CSE 504
Set of values
Together with a set of operations on these
values that possess certain properties
Types in Programming
Languages
• Let C be a class, with subclasses C1,...,Cn. Now, the body of function g (which is a client of
• Let f be a virtual method of class C
the function f) can be reused for arrays that
• We can now write client code that can apply the contain objects of type C1 or C2 or ... or Cn,or
function f uniformly to elements of an array, each of
which is a pointer to an object of type C1,...,Cn. even a mixture of these types.
CSE 307 Spring 2004 19 CSE 307 Spring 2004 20
R. Sekar R. Sekar
Type Equivalence Type Equivalence (contd.)
Structural equivalence: two types are Structural equivalence is the least restrictive
equivalent if they are defined by identical type Name equivalence is the most restrictive.
expressions. Declaration equivalence is in between
• array ranges usually not considered as part of the type TYP E t 1 = ARRAY [ 1 . . 1 0 ] o f I N T EGER; V AR v 1 : ARRAY
• record labels are considered part of the type.
Name equivalence: two types are equal if they
[ 1 . . 1 0 ] O F I N T EGER;
[ 1 . . 1 0 ] O F I N T EGER;
have the same name.
Declaration equivalence: two types are Structurally
equivalent?
Declaration
equivalent?
Name
equivalent?
equivalent if their declarations lead back to the t1, t2 Yes Yes No
same original type expression by a series of
v1, v2 Yes No No
redeclarations.
v3, v4 Yes Yes Yes
CSE 307 Spring 2004 21 CSE 307 Spring 2004 22
R. Sekar R. Sekar