|
|
|
Type Checking
Exercises
- Give the type rules for:
for-statements;
new-expressions; and
- array expressions.
- Assume you have a method
int m(int,int) and construct
the type proof for the program fragment:
int x,y;
y = 2;
x = m(3,y)+1;
- Consider a scenario, where we extend SJ with a
type
real that also has a +
operator.
Furthermore, we want int values to
be implicitly coerced into real values as needed.
Explain the implications for the type checker.
- A radical extension of the ESJ type system would allow a variable to be typed as:
A,B,C x;
which means that x may contain objects of either of the classes A, B, or C.
Types are thus finite sets of classes, rather than just single classes.
With the appropriate type rules, this will allow more programs to be
accepted as statically type correct.
Show examples of such type rules
for the ESJ syntax. Show that they a strictly more powerful than the
standard type system.
Do you like this new language?
- Study the code for type checking SJ programs.
Reading
Materials
Type Checking
|