Docsity

Discussion Section Notes Typing Rules, Judgments and Checking - Slides | CS 4610, Study notes of Programming Languages

Toggle sidebar
bg1
CS415 — Discussion Section Notes 6
Claire Le Goues
March 13, 2008
Any questions about scoping? Moving on...
1 Typing Rules, Judgements, and Checking
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.
2 SELF TYPE
What’s the difference between static and dynamic? As applied to type systems? As
applied to dispatch?
1
pf3

Partial preview of the text

Download Discussion Section Notes Typing Rules, Judgments and Checking - Slides | CS 4610 and more Study notes Programming Languages in PDF only on Docsity!

CS415 — Discussion Section Notes 6

Claire Le Goues

March 13, 2008

Any questions about scoping? Moving on...

1 Typing Rules, Judgements, and Checking

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.

2 SELF TYPE

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?