• Aucun résultat trouvé

Simply typed λ -calculus: typing rules

N/A
N/A
Protected

Academic year: 2022

Partager "Simply typed λ -calculus: typing rules"

Copied!
25
0
0

Texte intégral

(1)

Category theory to the rescue of type checking

Guilhem Moulin

February 15, 2010

(2)

Type checking

Simply typedλ-calculus Dependent typedλ-calculus

Category theory

(3)

Simply typed λ -calculus: types and terms

1 data Ty : Set where

2 ⋆ : Ty

3 ⇒ : Ty →Ty → Ty

5 Cxt : Set

6 Cxt = List Ty

8 data Tm : Set where

9 Var : Nat → Tm

10 @ : Tm → Tm→ Tm

11 λ : Tm → Tm

(4)

Simply typed λ -calculus: typing rules

Γ1, . . . ,Γn⊢Γi

Γ⊢a⇒b Γ⊢a Γ⊢b Γ,a⊢b

Γ⊢a⇒b

(5)

Simply typed λ -calculus: typing rules

Vari : Γ1, . . . ,Γn⊢Γi

f : Γ⊢a⇒b x: Γ⊢a f @x : Γ⊢b e : Γ,a⊢b

λe : Γ⊢a⇒b

(6)

Simply typed λ -calculus: typing rules

Vari : Γ1, . . . ,Γn⊢Γi

f : Γ⊢a⇒b x: Γ⊢a f @x : Γ⊢b e : Γ,a⊢b

λe : Γ⊢a⇒b

"_: _ ⊢ _": Cxt → Tm → Ty → Prop

(7)

Simply typed λ -calculus: type-checking algorithm

Decidability of typing:

1 decTS : (Γ: Cxt) → (a: Ty) → (t: Tm)

2 → (t: Γ ⊢ a) ∨ Not (t: Γ ⊢a)

(8)

Simply typed λ -calculus: type-checking algorithm

Decidability of typing:

1 decTS : (Γ: Cxt) → (a: Ty) → (t: Tm)

2 → (t: Γ ⊢ a) ∨ Not (t: Γ ⊢a)

Perform program extraction:

1 isTm : Cxt→ Ty → Tm→ Bool

(9)

Simply typed λ -calculus: type-checking algorithm

Decidability of typing:

1 decTS : (Γ: Cxt) → (a: Ty) → (t: Tm)

2 → (t: Γ ⊢ a) ∨ Not (t: Γ ⊢a)

Perform program extraction:

1 isTm : Cxt→ Ty → Tm→ Bool Correctness of type-checking:

1 corrTC: (Γ: Cxt) → (a: Ty)→ (t: Tm)

2 → t: Γ ⊢ a ↔ isTmΓ a t = true

(10)

What is dependent typed λ -calculus?

dependent function types: (x:A)⇒B(x) rather thanA⇒B

universeSet of “sets” (small types)

(11)

What is dependent typed λ -calculus?

dependent function types: (x:A)⇒B(x) rather thanA⇒B

universeSet of “sets” (small types) Here is a Coq example:

1 Inductive Vect (A:Set): ∀ n:nat, Set :=

2 | nil : Vect A0

3 | cons : ∀ n, A→ Vect A n → Vect A(n+1).

(12)

What is dependent typed λ -calculus?

dependent function types: (x:A)⇒B(x) rather thanA⇒B

universeSet of “sets” (small types) Here is a Coq example:

1 Inductive Vect (A:Set): ∀ n:nat, Set :=

2 | nil : Vect A0

3 | cons : ∀ n, A→ Vect A n → Vect A(n+1).

computation of types: may get a loop. We restrict to normal types

(13)

Decidability of the typing relation for dependent types

Very important:

Proof assistants type-checking algorithm = core of proof assistants like Coq or Agda

Constructive foundations the decidability of a:A is fundamental in constructivism based on Curry-Howard

(14)

Decidability of the typing relation for dependent types

Very important:

Proof assistants type-checking algorithm = core of proof assistants like Coq or Agda

Constructive foundations the decidability of a:A is fundamental in constructivism based on Curry-Howard

But it has been difficult to obtain clear correctness proofs.

Success approaches: normalisation by evaluationand category-theoretic models of dependent types.

(15)

Dependent typed λ -calculus: syntax

Normal and neutral rawterms:

non:=nen| λnon+1 |Πnon non+1 |U nen:=Var i (i <n) |nen@ non

(16)

Dependent typed λ -calculus: syntax

Normal and neutral rawterms:

non:=nen| λnon+1 |Πnon non+1 |U nen:=Var i (i <n) |nen@ non

Contexts and substitutions:

Cxt0 := [ ] Substm,0 :=him

Cxtn+1 := (Cxtn;non+1) Substm,n+1 :=hSubstm,n,nomi

(17)

Dependent typed λ -calculus: some rules

Γ :Cxtn A:TypeΓ (Γ;A) :Cxtn+1

Γ,∆ :Cxt A:TypeΓ γ : Γ→∆ a: ∆⊢A[γ]

hγ,ai: ∆→(Γ;A)

Γ :Cxt A:TypeΓ B:Type(Γ;A) b : (Γ;A)⊢B λb: Γ⊢ΠA B

(18)

Type-checking functions

We need to check contexts and types:

1 isCo: ∀ m, Cxtm →Bool

2 isSu: ∀ m n, Cxtm →Cxt n → Substm n→ Bool

3 isTy: ∀ n, Cxtn → No n→ Bool

4 isTm: ∀ n, Cxtn → No n→ No n→ Bool

(19)

A category with families (cwf) consists of:

a categoryC which has a terminal object: the category of contexts

a family-valued functor T :Cop →Fam, to model types, terms and substitutions

extra structure to model context comprehension

(20)

A category with families (cwf) consists of:

a categoryC which has a terminal object: the category of contexts

a family-valued functor T :Cop →Fam, to model types, terms and substitutions

extra structure to model context comprehension A ΠU-cwf has in addition to this:

extra structure to model Π

extra structure to model U

(21)

A category with families (cwf) consists of:

a categoryC which has a terminal object: the category of contexts

a family-valued functor T :Cop →Fam, to model types, terms and substitutions

extra structure to model context comprehension A ΠU-cwf has in addition to this:

extra structure to model Π

extra structure to model U

abstract data to ignore syntax problems

(22)

In our case

objects of C: contexts

arrow of C: substitutions.

T Γ = (TypeΓ,({t |t : Γ⊢A})A∈TypeΓ)

T γ = (A7→A[γ],(t 7→t[γ])A∈TypeΓ)

(23)

In our case

objects of C: contexts

arrow of C: substitutions.

T Γ = (TypeΓ,({t |t : Γ⊢A})A∈TypeΓ)

T γ = (A7→A[γ],(t 7→t[γ])A∈TypeΓ)

terminal object: [ ]

terminal arrows: empty substitutions

(24)

The Π U -cwf N of type-checked normal forms

Correctness of the algorithm iffN is an initial ΠU-cwf.

Difficult part: prove that

γ : ∆→Γ⇒t : Γ⊢A⇒t[γ] : ∆⊢A[γ].

(25)

The Π U -cwf N of type-checked normal forms

Correctness of the algorithm iffN is an initial ΠU-cwf.

Difficult part: prove that

γ : ∆→Γ⇒t : Γ⊢A⇒t[γ] : ∆⊢A[γ].

Solution: reducibility predicates

RedTmΓ (Π a b) t iff ∀∆, σ: ∆→Γ, ∀t, RedTma[σ] t

⇒RedTmb[hσ,ti] (app t[σ]t)

Références

Documents relatifs

Terms in η-long form present several advantages (see [JG95]) and every simply-typed term M can be put in η-long form with respect to a derivation of a judgement [Hue76].

A revised completeness result for the simply typed λµ-calculus using realizability semantics.. Karim Nour,

To identify potential targets of RNAi clones, we first generated all possible 21 bp fragments from the predicted sequence of each RNAi clone insert and then we searched for

/ La version de cette publication peut être l’une des suivantes : la version prépublication de l’auteur, la version acceptée du manuscrit ou la version de l’éditeur. Access

Stop considering anything can be applied to anything A function and its argument have different

Stop considering anything can be applied to anything A function and its argument have different behaviors.. Demaille Simply Typed λ-Calculus 12

The strong normalization theorem of second order classical natural deduction [20] is based on a lemma known as the correctness result, which stipulates that each term is in

Since the proofs in the implicative propositional classical logic can be coded by Parigot’s λµ-terms and the cut elimination corresponds to the λµ-reduction, the result can be seen as