Last time on Types ... I Modified ML with polymorphic types anywhere - - PowerPoint PPT Presentation

last time on types
SMART_READER_LITE
LIVE PREVIEW

Last time on Types ... I Modified ML with polymorphic types anywhere - - PowerPoint PPT Presentation

Last time on Types ... I Modified ML with polymorphic types anywhere Identity, Generalisation and Specialisation ` x : if ( x : ) 2 ( id ) ` M : if / 2 ftv ( ) ( gen ) ` M : 8 ( ) ` M : 8 ( ) ( spec ) `


slide-1
SLIDE 1

Last time on Types...

I Modified ML with polymorphic types anywhere

slide-2
SLIDE 2

Identity, Generalisation and Specialisation Γ ` x : π if (x : π) 2 Γ (id) Γ ` M : π Γ ` M : 8 α (π) if α / 2 ftv(Γ) (gen) Γ ` M : 8 α (π) Γ ` M : π[π0/α] (spec)

slide-3
SLIDE 3

Last time on Types...

I Modified ML with polymorphic types anywhere I Polymorphic λ-calculus

slide-4
SLIDE 4

PLC type system

Γ ` x : τ if (x : τ) 2 Γ (var) Γ, x : τ1 ` M : τ2 Γ ` λ x : τ1 (M) : τ1 ! τ2 if x / 2 dom(Γ) (fn) Γ ` M1 : τ1 ! τ2 Γ ` M2 : τ1 Γ ` M1 M2 : τ2 (app) Γ ` M : τ Γ ` Λ α (M) : 8 α (τ) if α / 2 ftv(Γ) (gen) Γ ` M : 8 α (τ1) Γ ` M τ2 : τ1[τ2/α] (spec)

slide-5
SLIDE 5

Last time on Types...

I Modified ML with polymorphic types anywhere I Polymorphic λ-calculus

I Λα (λx : α (x)) : ∀α(α → α)

I Decideability of typing for PLC

slide-6
SLIDE 6

Today...

I Results on reduction (semantics) of PLC I Encoding data types in PLC (part 1)

slide-7
SLIDE 7

Beta-reduction of PLC expressions

M beta-reduces to M0 in one step, M → M0 means M0 can be

  • btained from M (up to alpha-conversion, of course) by replacing

a subexpression which is a redex by its corresponding reduct. The redex-reduct pairs are of two forms: (λ x : τ (M1)) M2 → M1[M2/x] (Λ α (M)) τ → M[τ/α]. M →⇤ M0 indicates a chain of finitely † many beta-reductions.

(† possibly zero—which just means M and M0 are alpha-convertible).

M is in beta-normal form if it contains no redexes.

slide-8
SLIDE 8

Properties of PLC beta-reduction on typeable expressions

Suppose Γ ` M : τ is provable in the PLC type system. Then the following properties hold: Subject Reduction. If M ! M0, then Γ ` M0 : τ is also a provable typing.

slide-9
SLIDE 9

Subject reduction requires substitution lemma... Extra

Subject Reduction. If M ! M0, then Γ ` M0 : τ is also a provable typing. For example for: (λ x : σ (M1)) M2 ! M1[M2/x]

(app) (abs)

Γ, x : σ ` M1 : τ Γ ` λ x : σ (M1) : σ ! τ Γ ` M2 : σ Γ ` (λ x : σ (M1)) M2 : τ

  • !

Γ, x : σ ` M1 : τ Γ ` M2 : σ Γ ` M1[M2/x] : τ Lemma(substitution) If Γ, x : σ ` M1 : τ and Γ ` M2 : σ then Γ ` M1[M2/x] : τ. Proof By induction over the typing relation on M1.

slide-10
SLIDE 10

Properties of PLC beta-reduction on typeable expressions

Suppose Γ ` M : τ is provable in the PLC type system. Then the following properties hold: Subject Reduction. If M ! M0, then Γ ` M0 : τ is also a provable typing. Church Rosser Property. If M !⇤ M1 and M !⇤ M2, then there is M0 with M1 !⇤ M0 and M2 !⇤ M0. Strong Normalisation Property. There is no infinite chain M ! M1 ! M2 ! . . . of beta-reductions starting from M.

slide-11
SLIDE 11

Theorem 16, p.43 Extra

Church-Rosser (CR) + Strong Normalisation (SN) ⇒ exists unique beta-normal forms for typeable PLC expres- sions

I Existence: start from M and reduce any redexes... by

(SN) this must eventually stop

I Uniqueness: by (CR), if M →⇤ M1 and M →⇤ M2 then

M1

%

M

⇤: ⇤

$

M0 M2

⇤9

(where M1 →⇤ M0 and M2 →⇤ M0 are zero length β-reduction chanins if M1 and M2 are in β-normal form).

slide-12
SLIDE 12

Y-combinator Extra

Y = λf .((λx.f (x x)) (λx.f (x x)))

I Satisfies fixed-point combinator equation Y f = f (Y f ) I for some f , Y f does not have a beta-normal form

(see Remark 17, p.43, where f = id)

I Y is not typeable in PLC

Exercise (2 min). Show that Y id has an infinite β-reduction chain (i.e., no β-normal form)

slide-13
SLIDE 13
slide-14
SLIDE 14

PLC beta-conversion, =β

By definition, M =β M0 holds if there is a finite chain M − · − · · · − · − M0 where each − is either → or ←, i.e. a beta-reduction in one direction or the other. (A chain of length zero is allowed—in which case M and M0 are equal, up to alpha-conversion, of course.) Church Rosser + Strong Normalisation properties imply that, for typeable PLC expressions, M =β M0 holds if and only if there is some beta-normal form N with M →⇤ N ⇤← M0

slide-15
SLIDE 15

Data types in PLC (Section 4.4)

I define a suitable PLC type for the data I define suitable PLC expressions for values & on the data I show PLC expressions have correct typings & behaviour

(use the semantics)

slide-16
SLIDE 16

Polymorphic booleans

bool def = ∀ α (α → (α → α)) True def = Λ α (λ x1 : α, x2 : α (x1)) False def = Λ α (λ x1 : α, x2 : α (x2)) if def = Λ α (λ b : bool, x1 : α, x2 : α (b α x1 x2))

slide-17
SLIDE 17

Exercise (5 min) Given Γ ` M1 : bool , Γ ` M2 : τ , Γ ` M3 : τ and      M1 !⇤ True M2 !⇤ N2 M3 !⇤ N3

slide-18
SLIDE 18

Exercise (5 min) Given Γ ` M1 : bool , Γ ` M2 : τ , Γ ` M3 : τ and      M1 !⇤ True M2 !⇤ N2 M3 !⇤ N3 then if τ M1 M2 M3 !⇤ ?

slide-19
SLIDE 19
slide-20
SLIDE 20
slide-21
SLIDE 21

Polymorphic lists

↵ list def = ∀ ↵0 (↵0 → (↵ → ↵0 → ↵0) → ↵0) Nil def = Λ ↵, ↵0 ( x0 : ↵0, f : ↵ → ↵0 → ↵0 (x0)) Cons def = Λ↵(x : ↵, ` : ↵ list(Λ↵0( x0 : ↵0, f : ↵ → ↵0 → ↵0( f x (` ↵0 x0 f )))))

slide-22
SLIDE 22