Академический Документы
Профессиональный Документы
Культура Документы
Martin Mehlmann
(mehlmann@informatik.uni-freiburg.de)
1 / 10
Exercise 1
I
Code given:
s = "some random string";
s.x = 42;
s.x;
Output of Rhino:
/tmp/rhino1_7R1$ java -jar js.jar
Rhino 1.6 release 7 2007 08 19
js> s = "some random string";
some random string
js> s.x = 42;
42
js> s.x;
js>
2 / 10
Exercise 1
I
3 / 10
Exercise 2
(a) 1 + true is not type correct: true has type boolean, but
+ adds two expressions of type int.
(b) 23 + (47 11) has type int:
(INT)
(INT)
(ADD)
` 23 : int
` 47 : int
` 11 : int
` 47 11 : int
` 23 + (47 11) : int
(IN
(SUB)
(NOT)
(NOT)
` false : boolean
` !false : boolean
` !(!false) : boolean
4 / 10
Exercise 2
(VAR)
(NOT)
5 / 10
Exercise 3
(a) 23 + (47 11) 23 + 36 59
(B-SUB)
(B-ADD-R)
47 11 36
23 + (47 11) 23 + 36
(B-ADD)
23 + 36 59
59 is a value
(b) (1 + 1) + true 2 + true
(B-ADD)
(B-ADD-L)
1 + 1 2
(1 + 1) + true 2 + true
6 / 10
Exercise 4
Lemma (Normalization)
For every expression e0 , there exists an expression en such that
e0 e1 e2 . . . en1 en
and no expression en+1 exists with en en+1 .
Proof. Define the size of an expression as follows:
if e = x or e = b or e = dme
1
0
00
size(e) = 1 + size(e ) + size(e ) if e = e0 + e00
1 + size(e0 )
if e = !e0
We can easily prove that e e0 implies size(e) > size(e0 ).
(The proof is by induction on the derivation of e e0 .)
7 / 10
Exercise 4
8 / 10
Exercise 4
n = 0. Then ` en : t by assumption.
9 / 10
Exercise 4
Theorem (Type soundness)
If ` e0 : t then there exists a value en such that ` en : t and
e0 e1 e2 . . . en1 en
10 / 10