A direct translation of the Simply Typed Lambda Calculus into - - PowerPoint PPT Presentation

a direct translation of the simply typed lambda calculus
SMART_READER_LITE
LIVE PREVIEW

A direct translation of the Simply Typed Lambda Calculus into - - PowerPoint PPT Presentation

A direct translation of the Simply Typed Lambda Calculus into C++-templates Markus Michelbrink Department of Computer Science University of Wales, Swansea Joint work with Magne Haveraaen, Bergen TYPES 2006 Nottingham, April 2006 A direct


slide-1
SLIDE 1

A direct translation of the Simply Typed Lambda Calculus into C++-templates

Markus Michelbrink Department of Computer Science University of Wales, Swansea Joint work with Magne Haveraaen, Bergen TYPES 2006 Nottingham, April 2006

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 1/9

slide-2
SLIDE 2

Basic ideas

One ground type: ⋆ ≈ class template < class X_s > struct someClass {...;}; is of type ⋆ → ⋆, template < template < class X_s > class X_nss > struct someClass {...;}; is of type (⋆ → ⋆) → ⋆, template < template < class X_s > class X_nss, class X_s > struct someClass {...;}; is of type (⋆ → ⋆) → ⋆ → ⋆, ...

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 2/9

slide-3
SLIDE 3

Basic ideas

η-expand and abstract from free variables: vs : ⋆ → λvs.vs : ⋆ → ⋆ vnss : ⋆ → ⋆ → λvnss, vs.vnssvs : (⋆ → ⋆) → ⋆ → ⋆ The variable vs : ⋆ translates to template < class X_s > struct V_s {typedef typename X_s::result result;}; The variable vnss ∼βη λvs.vnssvs : ⋆ → ⋆ translates to template < template < class X_s > class X_nss, class X_s > struct V_nss {typedef typename X_nss<X_s>::result result;};

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 3/9

slide-4
SLIDE 4

Basic ideas

Application is instantiation: The term vnssvs : ⋆ translates to template < template < class X_s > class X_nss, class X_s > struct V_nssVs {typedef typename V_nss<X_nss,V_s<X_s>>::result result;}; If v ∈ FV (t): abstraction does not change anything. E.g. λvs.vnssvs : ⋆ → ⋆ translates to the template above. If v ∈ FV (t): add a further parameter. E.g. λws.vnssvs : ⋆ translates to template < class Y_s, template < class X_s > class X_nss, class X_s > struct V_nssVs {typedef typename V_nss<X_nss,V_s<X_s>>::result result;};

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 4/9

slide-5
SLIDE 5

Basic ideas

Constants of ground type are given by struct constant_int {typedef int result;}; struct constant_double {typedef double result;}; Theorem: "The translation of every closed term of ground type evaluates to the value of the closed term."

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 5/9

slide-6
SLIDE 6

λ into λ

T(vi : A1 . . . Am → ⋆) = λvi+1, . . . , vi+m.vivi+1 . . . vi+m T(t0) = λv1 . . . vm.t′

0 then

T(t0t1) = λv2 . . . vm.t′

  • some α-conversion

[v1 := T(t1)] T(λv.t) = λv.T(t) for v ∈ FV (t) T(λv.t) = λvnew.T(t) for v ∈ FV (t) where A1 . . . Am → ⋆ := A1 → (A2 . . . (Am → ⋆) . . .).

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 6/9

slide-7
SLIDE 7

Properties

T is welldefined on welltyped terms i.e. t : A → B ⇒ T(t) = λv : A.t′ for some t′. T(t) is welltyped and Type(T(t)) = Type(t) FV (T(t)) = FV (t) T(t) ∼αβη t Adding constants of ground type c0, c1, . . . : ⋆ we get T(t) ∼β t for every closed term t : ⋆.

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 7/9

slide-8
SLIDE 8

What it is ...

In terms of the lambda cube we have (✷, ✷) but without (⋆, ⋆)! Where ⋆ ≈ class. Do we have more?

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 8/9

slide-9
SLIDE 9

What it is ...

We can build template < int i > struct someClass {enum ...}; ≈ (i : int) → class. Dependent types (⋆, ✷) ? Function templates are build similar to class templates: template < int i > int justTheIdentity() {return i;}; ≈ int → int. Simple Types (⋆, ⋆) ? template < class X > X someFunction() {...}; ≈ (X : class) → X. Polymorphism (✷, ⋆)? No, we can not use them as parameters!

A direct translation of the Simply Typed Lambda Calculus into C++-templates – p. 9/9