Week 7/43
Exercises on type checking
- Give the type rules for:
- Construct the type proof for the statement:
Cons x,y; int z; x = new Cons(z+1,y)
- Consider a scenario, where we extend JOOS with a type
float
that also has a + operator. Furthermore, int
values may be coerced into float values as needed. Explain
the implications for the type checker.
- A radical extension of the JOOS type system allows 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 JOOS syntax. Show that they are strictly more powerful than the
standard type system. Do you like this new language?
- Study the code for type checking JOOS programs.
|