




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Advanced Topics in Computer Graphics; Subject: Computer Science; University: University of California-Santa Cruz; Term: Unknown 2004;
Typology: Study notes
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















13 Jan 2004^
290G - Lecture 3a
290G - Lecture 3a
-^ Programming language •^ Semantics
-^ Type language •^ Some programs have types^ –^ (according to type rules) •^ Soundness Theorem:
-^ If A^ d^ e:
τ^ ande^ →^
∗d, then Aβ^
d^ d:τ
-^ Untypable program: 3 + (
290G - Lecture 3a
e ise with all type
type inference problem.
290G - Lecture 3a
290G - Lecture 3a
1 1 2 2 1 2 1 2 1 1 1 1
2 2 2 2
3 3 1 2
1 2
3 1 2
: : 1 2 3 2
(^ )^
,^ :^ : :.^ :^
: : :^
: :^
: int^
int i : int^
: int^
if^ : x
x x
A^ x e A e
A x
A xe A^ x
A^ x e
A^ e^ e A^ e A^ e
A^ e A^ e
A^ e AA
e^ e
A^ e^ e^ τ^ τ τ τ β e α
α^ τ αλ^
α^ τ
β τ τ
τ τ
τ τ^ τ
ττ^ =^ → τ^ τ =
→ = = =^
=
d d d d^
d^
d d d^
d d^
d d^ d
d
-^ Sidestep the problems by introducing explicit unknownsand constraints
290G - Lecture 3a
1 1 2 2 1 2 1 2 1 1 1 1
2 2 2 2
3 3 1 2
1 2
3 1 2
: : 1 2 3 2
(^ )^
,^ :^ : :.^ :^
: : :^
: :^
: int^
int i : int^
: int^
if^ : x
x x
A^ x e A e
A x
A xe A^ x
A^ x e
A^ e^ e A^ e A^ e
A^ e A^ e
A^ e AA
e^ e
A^ e^ e^ τ^ τ τ τ β e α
α^ τ αλ^
α^ τ
β τ τ
τ τ
τ τ^ τ
ττ^ =^ → τ^ τ =
→ = = =^
=
d d d d^
d^
d d d^
d d^
d d^ d
d
-^ Type assumption for variable x is a fresh variable
290G - Lecture 3a
1 1 2 2 1 2 1 2 1 1 1 1
2 2 2 2
3 3 1 2
1 2
3 1 2
: : 1 2 3 2
(^ )^
,^ :^ : :.^ :^
: : :^
: :^
: int^
int i : int^
: int^
if^ : x
x x
A^ x e A e
A x
A xe A^ x
A^ x e
A^ e^ e A^ e A^ e
A^ e A^ e
A^ e AA
e^ e
A^ e^ e^ τ^ τ τ τ β e α
α^ τ αλ^
α^ τ
β τ τ
τ τ
τ τ^ τ
ττ^ =^ → τ^ τ =
→ = = =^
=
d d d d^
d^
d d d^
d d^
d d^ d
d
-^ Hypotheses are all arbitrary^ –^ Can always complete a derivation, pending constraint resolution
290G - Lecture 3a
290G - Lecture 3a α^ β^ γ^ =^ → α^ γ^ β=^ →^ intβ=
-^ A solution is
int^ int,
int,
int
α
β
γ =^ →
=^
=
290G - Lecture 3a
290G - Lecture 3a
16 / 28
-^ We distinguish
solved equations
-^ Each rule manipulates only unsolved equations.
{^ }^
{^ }
{^
}^
{^
}
{^ 1 2 3 }
1 3 2 4
4
{^ }
[^ /^ ]
,
S int^ int
S
S
S
S
S
S
S α^ α α^ τ
τ^ α^
α^ τ
τ^ τ^
τ^ τ
τ^ τ^ τ^
τ
∪^ =^
⇒ ∪^ =^
⇒^
∪^ ≅
∪^ →^
=^ →^
⇒^ ∪^
=^ =
∪^ =^
⇒
290G - Lecture 3a
17 / 28
-^ Rules 1 and 4 eliminate trivial constraints. •^ Rule 1 is applied in preference to rule 2^ –^ the only such possible conflict
{^ }^
{^ }
{^
}^
{^
}
{^ 1 2 3 }
1 3 2 4
4
{^ }
[^ /^ ]
,
S int^ int
S
S
S
S
S
S
S α^ α α^ τ
τ^ α^
α^ τ
τ^ τ^
τ^ τ
τ^ τ^ τ^
τ
∪^ =^
⇒ ∪^ =^
⇒^
∪^ ≅
∪^ →^
=^ →^
⇒^ ∪^
=^ =
∪^ =^
⇒
290G - Lecture 3a
19 / 28
-^ Rule 3 applies structural equality to non-trivial terms.
{^ }^
{^ }
{^
}^
{^
}
{^ 1 2 3 }
1 3 2 4
4
{^ }
[^ /^ ]
,
S int^ int
S
S
S
S
S
S
S α^ α α^ τ
τ^ α^
α^ τ
τ^ τ^
τ^ τ
τ^ τ^ τ^
τ
∪^ =^
⇒ ∪^ =^
⇒^
∪^ ≅
∪^ →^
=^ →^
⇒^ ∪^
=^ =
∪^ =^
⇒
290G - Lecture 3a
20 / 28
-^ Each rule preserves the set of solutions.^ –^ Rules 1 and 4 eliminate trivial constraints.^ –^ Rule 2 substitutes equals for equals.^ –^ Rule 3 is the definition of equality on function types.
{^ }^
{^ }
{^
}^
{^
}
{^ 1 2 3 }
1 3 2 4
4
{^ }
[^ /^ ]
,
S int^ int
S
S
S
S
S
S
S α^ α α^ τ
τ^ α^
α^ τ
τ^ τ^
τ^ τ
τ^ τ^ τ^
τ
∪^ =^
⇒ ∪^ =^
⇒^
∪^ ≅
∪^ →^
=^ →^
⇒^ ∪^
=^ =
∪^ =^
⇒