

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Any questions about scoping? Moving on...
Some simple exercises for the class:
What is the type judgement for arithmetic (adding)?
What is the typing judgement for IF statements?
What does the following rule mean? How do we read it? Discuss!
...That’s all very nice. But how on earth does that turn into code? PA4, after all, includes a ”type checker,” which really just enforces the rules we’ve written in Greek.
What’s the difference between static and dynamic? As applied to type systems? As applied to dispatch?
In our type system, we define soundness as follows:
∀ E. dynamic type(E) ≤ static type(E)
Why does this work?
Consider the following piece of code:
Listing 1: SELF TYPE problem
class A { | class B inherits A { modifying_op() : A { | (* ... (^) ) { ( ... *) | name : String { self; | name; } | } } | }; }; |
myObject : B <- (new B).modifying_op(); (* badness (^) *)
What’s wrong here? Solution: we add SELF TYPE to the language, and change our code:
Listing 2: SELF TYPE solution modifying_op() : SELF_TYPE { { (* ... *) self; }
Note: Unlike other typenames, SELF TYPE means different things in different parts of the code. What changes do we need to make to our type system for that to work?
Which of the following are legal?
Listing 3: SELF TYPE placement
(* 1 *) class SELF_TYPE inherits Q ...
(* 2 *) s : SELF_TYPE <- ...
(* 3 *) s <- new SELF_TYPE
Can SELF TYPE be a method argument type?