Bounded Quantified Types - Lecture Notes | CMPS 290, Study notes of Computer Graphics

Material Type: Notes; Class: Advanced Topics in Computer Graphics; Subject: Computer Science; University: University of California-Santa Cruz; Term: Unknown 2005;

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-c4r-1
koofers-user-c4r-1 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Bounded Quantified Types
Types and Programming Languages, Spring 2005, SoE UCSC
presenter Jessica Gronski
scribe Avik Chaudhuri
May 19, 2005
1 Looking back
We recalled the differences in programming styles when using objects versus ADTs, in particular the
expressiveness problem with objects under pure existential types when defining (strong) binary operations.
Such questions came up in Kim Bruce’s talk on May 17 as well. We agreed that more information on the
type variable in existential types is useful in order to write interesting programs; bounded existentials
provide the means to pass such information.
2 On the board
The syntax of the pure lambda calculus with bounded quantified types has the following syntax.
Terms t::= x(variable)
|λx :T.t (abstraction)
|t t (application)
|ΛX <:T.t (type abstraction)
|t[T] (type application)
| {⋆T, t}as T(packing)
|let {X, x}=tin t(unpacking)
Types T::= X(type variable)
|Top (maximum type)
|TT(function type)
| X <:T. T (universal type)
| {∃X <:T, T }(existential type)
Environments Γ ::= (empty)
|Γ, x :T(variable type declaration)
|Γ, X <:T(type bound declaration)
1
pf2

Partial preview of the text

Download Bounded Quantified Types - Lecture Notes | CMPS 290 and more Study notes Computer Graphics in PDF only on Docsity!

Bounded Quantified Types

Types and Programming Languages, Spring 2005, SoE UCSC

presenter Jessica Gronski

scribe Avik Chaudhuri

May 19, 2005

1 Looking back

We recalled the differences in programming styles when using objects versus ADTs, in particular the expressiveness problem with objects under pure existential types when defining (strong) binary operations. Such questions came up in Kim Bruce’s talk on May 17 as well. We agreed that more information on the type variable in existential types is useful in order to write interesting programs; bounded existentials provide the means to pass such information.

2 On the board

The syntax of the pure lambda calculus with bounded quantified types has the following syntax. Terms t ::= x (variable) | λx : T.t (abstraction) | t t (application) | ΛX <: T.t (type abstraction) | t [T ] (type application) | {⋆T, t} as T (packing) | let {X, x} = t in t (unpacking)

Types T ::= X (type variable) | Top (maximum type) | T → T (function type) | ∀X <: T. T (universal type) | {∃X <: T, T } (existential type)

Environments Γ ::= ∅ (empty) | Γ, x : T (variable type declaration) | Γ, X <: T (type bound declaration)

For a moment, the syntax looked funny because the bounding symbol <: occured in three places (type abstraction, universal and existential type) instead of four (packing?). However it was observed that in the term {⋆T 1 , t} as T 2 , T 2 would be of the form {∃X <: T 3 , T 4 }, hence satisfying our intuitive alarm. Before going further, we tried our hands at subtyping pure (unbounded) quantified types.

Γ, X ⊢ T <: S (<: ∃) Γ ⊢ ∃X.T <: ∃X.S

Γ, X ⊢ T <: S

Γ ⊢ ∀X.T <: ∀X.S

It was agreed that there was no need for rules with different bound variables, since these could be renamed without affecting the meaning of the quantified type. We then moved to writing some of the interesting type rules.

(Ax <:) X <:^ T^ ∈^ Γ Γ ⊢ X <: T

Γ, X <: T ⊢ S 1 <: S 2 (∃ <:◦) Γ ⊢ {∃X <: T, S 1 } <: {∃X <: T, S 2 }

Γ, X <: T ⊢ S 1 <: S 2

Γ ⊢ ∀X <: T. S 1 <: ∀X <: T. S 2

Γ ⊢ T 1 <: T 2 Γ, X <: T 1 ⊢ S 1 <: S 2

Γ ⊢ {∃X <: T 1 , S 1 } <: {∃X <: T 2 , S 2 }

Γ ⊢ T 2 <: T 1 Γ, X <: T 2 ⊢ S 1 <: S 2

Γ ⊢ ∀X <: T 1. S 1 <: ∀X <: T 2. S 2

Γ, X <: T ⊢ t 2 : T 2 (∀E) Γ ⊢ ΛX <: T. t 2 : ∀X <: T. T 2

(∀I) Γ^ ⊢^ t^ :^ ∀X <:^ T^ ′. T^ ′′^ Γ^ ⊢^ T <:^ T^ ′ Γ ⊢ t [T ] : [X 7 → T ]T ′′

The first rule is straightforward. The second and third rules assume that the quantified type variables have the same bounds. The fourth and fifth rules are generalizations of these, where the bounds may be different. In such rules, the usual notions of covariance and contravariance apply. The sixth and seventh rules introduce and eliminate type abstractions. Similar rules can be written to introduce and eliminate packages.

Exercise Try encoding existentials with bounded universal types alone (i.e., find encodings for exis- tential types, packing and unpacking in terms of the rest of the calculus).