Beruflich Dokumente
Kultur Dokumente
EXPRESSIONS
• “if two type expressions are equal
then return a certain type else return
type_error”.
• Therefore we should have a precise
definition of when two type
expressions are equivalent.
• Ambiguities may arise when names
are given to type expressions and
the names are then used in
subsequent type expression.
• The notion of type equivalence
implemented by compilers can often
be explained using two concepts .
STRUCTURAL EQUIVALENCE.
NAME EQUIVALENCE.
STRUCTURAL EQUIVALENCE OF
TYPE EXPRESSIONS
• As long as type expressions are built
from basic types and constructors, a
natural notion of equivalence
between two type expressions is
structural equivalence.
• If two expressions are either the
same basic type, or are formed by
applying the same constructor to
structurally equivalent types.
• That is two type expressions are
structurally equivalent if and only if
• For example
The type expression integer is
equivalent only to integer bcoz they
are the same basic type.
pointer(integer) is equivalent only to
pointer(integer) bcoz the two are
formed by applying the same
constructor pointer to equivalent
types.
1. Function sequiv(s,t): boolean;
begin
3. If s and t are the same basic type then
4. Return true
5. Else if s=array(s1,s2) and t=array(t1,t2) then
6. Return sequiv(s1,t1) and sequiv(s2,t2)
7. Else if s=s1*s2 and t=t1*t2 then
8. Return sequiv(s1,t1) and sequiv(s2,t2)
9. Else if s=pointer(s1) and t=pointer(t1) then
10.Return sequiv(s1,t1)
11.Else if s= s1 s2 and t= t1 t2 then
12.Return sequiv(s1,t1) and squiv(s2,t2)
else
14.Return false
end
• For checking the structural equivalence
of type expressions, we can find a
representation for type expressions that
is significantly more compact than the
type graph notion.
BASIC TYPES
ENCODING
TYPE EXPRESSION
ENCODING
char
000000 0001
freturns(char)
000011 0001
pointer(freturns(char))
000111 0001
array(pointer(freturns(char)))
100111 0001
next last p q
r
cell
CYCLES IN REPRESENTATION
OF TYPES
x
x
x x x
x
cell
Thank you