• Aucun résultat trouvé

A logical framework for incremental type-checking

N/A
N/A
Protected

Academic year: 2022

Partager "A logical framework for incremental type-checking"

Copied!
112
0
0

Texte intégral

(1)

A logical framework for incremental type-checking

Matthias Puech1,2 Yann R´egis-Gianas2

1Dept. of Computer Science, University of Bologna

2University Paris 7, CNRS, and INRIA, PPS, teamπr2

?January 2011?

PPS – Groupe de travail th´eorie des types et r´ealisabilit´e

(2)

A paradoxical situation

Observation

We have powerful tools to mechanize the metatheory of (proof) languages

. . . And yet,

Workflow of programming and formal mathematics is still largely inspired by legacy software development (emacs,make,svn, diffs. . . )

Isn’t it time to make these tools metatheory-aware?

(3)

A paradoxical situation

Observation

We have powerful tools to mechanize the metatheory of (proof) languages

. . . And yet,

Workflow of programming and formal mathematics is still largely inspired by legacy software development (emacs,make,svn, diffs. . . )

Isn’t it time to make these tools metatheory-aware?

(4)

A paradoxical situation

Observation

We have powerful tools to mechanize the metatheory of (proof) languages

. . . And yet,

Workflow of programming and formal mathematics is still largely inspired by legacy software development (emacs,make,svn, diffs. . . )

Isn’t it time to make these tools metatheory-aware?

(5)

Incrementality in programming & proof languages

Q :

Do you spend more timewritingcode oreditingcode?

Today, we use:

I separate compilation

I dependency management

I version control on the scripts

I interactive toplevel with rollback (Coq)

(6)

Incrementality in programming & proof languages

(7)

Incrementality in programming & proof languages

(8)

Incrementality in programming & proof languages

(9)

Incrementality in programming & proof languages

(10)

Incrementality in programming & proof languages

(11)

Incrementality in programming & proof languages

(12)

Incrementality in programming & proof languages

(13)

Incrementality in programming & proof languages

(14)

In an ideal world. . .

I Edition should be possible anywhere

I The impact of changes visible “in real time”

I No need for separate compilation, dependency management

Types are good witnesses of this impact

Applications

I non-linear user interaction

I tactic languages

I type-directed programming

I typed version control systems

(15)

In an ideal world. . .

I Edition should be possible anywhere

I The impact of changes visible “in real time”

I No need for separate compilation, dependency management

Types are good witnesses of this impact

Applications

I non-linear user interaction

I tactic languages

I type-directed programming

I typed version control systems

(16)

In an ideal world. . .

I Edition should be possible anywhere

I The impact of changes visible “in real time”

I No need for separate compilation, dependency management

Types are good witnesses of this impact

Applications

I non-linear user interaction

I tactic languages

I type-directed programming

(17)

Menu

The big picture Our approach

Why not memoization?

A popular storage model for repositories Logical framework

Positionality The language

From LF to NLF

NLF: Syntax, typing, reduction Architecture

(18)

Menu

The big picture Our approach

Why not memoization?

A popular storage model for repositories Logical framework

Positionality The language

From LF to NLF

NLF: Syntax, typing, reduction Architecture

(19)

A logical framework for incremental type-checking

Yes, we’re speaking about (any) typed language.

A type-checker

val check : env →term →types → bool

I builds and checks the derivation (on the stack)

I conscientiously discards it

i

i

i

e

AB, BC, A`BC Ax AB, BC, A`ABAx

AB, BC, A`AAx AB, BC, A`B e AB, BC, A`C

AB, BC`AC AB`(BC)AC

`(AB)(BC)AC

(20)

A logical framework for incremental type-checking

Yes, we’re speaking about (any) typed language.

A type-checker

val check : env →term →types → bool

I builds and checks the derivation (on the stack)

I conscientiously discards it

i

i

i

e

AB, BC, A`BC Ax AB, BC, A`ABAx

AB, BC, A`AAx AB, BC, A`B e AB, BC, A`C

AB, BC`AC AB`(BC)AC

`(AB)(BC)AC

(21)

A logical framework for incremental type-checking

Yes, we’re speaking about (any) typed language.

A type-checker

val check : env →term →types → bool

I builds and checks the derivation (on the stack)

I conscientiously discards it

true

(22)

A logical framework for incremental type-checking

Goal Type-check a large derivation taking advantage of the knowledge from type-checking previous versions

Idea Remember all derivations!

Q Do we really need faster type-checkers? A Yes, since we implemented these ad-hoc fixes.

(23)

A logical framework for incremental type-checking

Goal Type-check a large derivation taking advantage of the knowledge from type-checking previous versions

Idea Remember all derivations!

Q Do we really need faster type-checkers?

A Yes, since we implemented these ad-hoc fixes.

(24)

The big picture

version management script files

parsing type-checking

I AST representation

I Typing annotations

(25)

The big picture

version management

script files parsing

type-checking

I AST representation

I Typing annotations

(26)

The big picture

script files

version management

parsing type-checking

I AST representation

I Typing annotations

(27)

The big picture

script files parsing

version management type-checking

I AST representation

I Typing annotations

(28)

The big picture

script files parsing

version management type-checking

I AST representation

I Typing annotations

(29)

The big picture

user interaction parsing

version management type-checking

I AST representation

I Typing annotations

(30)

The big picture

user interaction parsing

type-checking

version management

I AST representation

I Typing annotations

(31)

The big picture

user interaction parsing

incremental type-checking version management

I AST representation

I Typing annotations

(32)

Menu

The big picture Our approach

Why not memoization?

A popular storage model for repositories Logical framework

Positionality The language

From LF to NLF

NLF: Syntax, typing, reduction Architecture

(33)

Memoization maybe?

let rec check env t a = matcht with

| ... → ... false

| ... → ... true and infer env t =

matcht with

| ... → ... None

| ... → ... Some a

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(34)

Memoization maybe?

let table =ref ([] : environ × term×types)in let rec check env t a =

if List .mem (env,t,a) ! table then true else matchtwith

| ... → ... false

| ... → ... table := (env, t ,a )::! table ; true and infer env t =

try List . assoc (env, t) ! table with Not found→ matchtwith

| ... → ... None

| ... → ... table := (env, t ,a )::! table ; Some a

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(35)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(36)

Memoization maybe?

+ lightweight

+ efficient implementation

– imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(37)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(38)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(39)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut)

– introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(40)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(41)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(42)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation + gives good reasons to go on

(43)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

+ gives good reasons to go on

(44)

Memoization maybe?

+ lightweight

+ efficient implementation – imperative

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1 wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn

Γ1`J wfΓn[Jn][J]

– external to the logic (meta-cut) – introduces a dissymmetry

What if I wante.g. the weakening property to be taken into account?

– syntactic comparison

– still no trace of the derivation

(45)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

v1

(46)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

/

/bar

/bar/c'

v1

/foo

/foo/a /bar/b

(47)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

/

/bar

/bar/c'

v1

(48)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

/

/bar

/bar/c'

v1

v2

(49)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

/

/bar

99dcf1d 46f9c2 923ace3

c328e8f d54c809

6e4f99a

4244e8a

cf189a6

e33478f

/bar/c'

v1

v2

820e7ab

a85f0b77

(50)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

/

/bar

99dcf1d 46f9c2 923ace3

c328e8f d54c809

6e4f99a

4244e8a

cf189a6

e33478f 99dcf1d → "Hello World"

d54c809 → 46f9c2, 923ace3 6ef99a → 99dcf1d 4244e8a → 6e4f99a, d54c809 cf189a6 → 46f9c2, c328e8f ...

/bar/c'

v1

v2

820e7ab

a85f0b77

(51)

A popular storage model for repositories

/

/foo /bar

/foo/a /bar/b /bar/c

/

/bar

99dcf1d 46f9c2 923ace3

c328e8f d54c809

6e4f99a

4244e8a

cf189a6

e33478f 99dcf1d → "Hello World"

d54c809 → 46f9c2, 923ace3 6ef99a → 99dcf1d 4244e8a → 6e4f99a, d54c809 cf189a6 → 46f9c2, c328e8f ...

/bar/c'

v1

v2

820e7ab

a85f0b77 a85f0b77

(52)

A popular storage model for repositories

The repositoryR is a pair (∆, x):

∆ :x7→(Commit (x×y) |Tree~x |Blob string) with the invariants:

I if (x,Commit (y, z))∈∆ then

I (y,Tree t)

I (z,Commit(t, v))

I if (x,Tree(~y))∈∆ then

for all yi, either (yi,Tree(~z)) or (yi,Blob(s))∈∆

Let’s do the same with proofs

(53)

A popular storage model for repositories

The repositoryR is a pair (∆, x):

∆ :x7→(Commit (x×y) |Tree~x |Blob string) with the invariants:

I if (x,Commit (y, z))∈∆ then

I (y,Tree t)

I (z,Commit(t, v))

I if (x,Tree(~y))∈∆ then

for all yi, either (yi,Tree(~z)) or (yi,Blob(s))∈∆

Let’s do the same with proofs

(54)

A typed repository of proofs

v1 - - : ⊢ C

λ- : ⊢(A∧B)→C -,- : ⊢ A∧B π₁ : A∧B⊢C π₂ : ⊢A π₃ : ⊢B

(55)

A typed repository of proofs

- - : ⊢ C v1

- - : ⊢ C λ- : ⊢(A∧B)→C

-,- : ⊢ A∧B -,- : ⊢ A∧B

π₁ : A∧B⊢C π₂ : ⊢A π₃ : ⊢B

π₃' : ⊢B

λ- : ⊢(A∧B)→C

π₁ : A∧B⊢C π₂ : ⊢A

(56)

A typed repository of proofs

- - : ⊢ C v1

- - : ⊢ C λ- : ⊢(A∧B)→C

-,- : ⊢ A∧B -,- : ⊢ A∧B

π₁ : A∧B⊢C π₂ : ⊢A π₃ : ⊢B

π₃' : ⊢B

(57)

A typed repository of proofs

- - : ⊢ C v1

v2 - - : ⊢ C

λ- : ⊢(A∧B)→C

-,- : ⊢ A∧B -,- : ⊢ A∧B

π₁ : A∧B⊢C π₂ : ⊢A π₃ : ⊢B

π₃' : ⊢B

(58)

A typed repository of proofs

- - : ⊢ C v1

v2 - - : ⊢ C

λ- : ⊢(A∧B)→C

-,- : ⊢ A∧B -,- : ⊢ A∧B

π₁ : A∧B⊢C π₂ : ⊢A π₃ : ⊢B

π₃' : ⊢B

x y z

t

v w

s r

q u p

(59)

A typed repository of proofs

x=. . . :AB`C y=. . . :`A z=. . . :`B

t=λaA∧B·x:`ABC u= (y, z) : `AB

v=t u:`C

w=Commit(v, w1) :Version

(60)

A typed repository of proofs

x=. . . :AB`C y=. . . :`A z=. . . :`B

t=λaA∧B·x:`ABC u= (y, z) : `AB

v=t u:`C

w=Commit(v, w1) :Version , w

(61)

A typed repository of proofs

x=. . . :AB`C y=. . . :`A z=. . . :`B

t=λaA∧B·x:`ABC u= (y, z) : `AB

v=t u:`C

w=Commit(v, w1) :Version p=. . . :`B

q= (y, p) :`AB r=t q:`C

s=Commit(r, w) :Version

(62)

A typed repository of proofs

x=. . . :AB`C y=. . . :`A z=. . . :`B

t=λaA∧B·x:`ABC u= (y, z) : `AB

v=t u:`C

w=Commit(v, w1) :Version p=. . . :`B

q= (y, p) :`AB r=t q:`C

s=Commit(r, w) :Version , s

(63)

A typed repository of proofs

...

val is : envproptype val conj : proppropprop

val pair : is α βisα γ isα(conj β γ) val version : type

val commit : is nil Cversionversion ...

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

w

(64)

A typed repository of proofs

...

val is : envproptype val conj : proppropprop

val pair : is α βisα γ isα(conj β γ) val version : type

val commit : is nil Cversionversion ...

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

let p = ... : is nil B

let q = pair y p : is nil (conj A B)in let r = t q : is nil C

(65)

A typed repository of proofs

...

val is : envproptype val conj : proppropprop

val pair : is α βisα γisα(conj β γ) val version : type

val commit : is nil Cversionversion ...

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

let p = ... : is nil B

let q = pair y p : is nil (conj A B)in let r = t q : is nil C

(66)

A logical framework for incremental type-checking

LF [Harper et al. 1992] provides a way to represent and validate syntax, rules and proofs by means of a typedλ-calculus. But we need a little bit more:

. . .

letu = pair y z : is nil (conj A B)in letv = app t u : is nil Cin . . .

1. definitions / explicit substitutions 2. type annotations on application spines 3. fully applied constants / η-long NF

4. Naming of all application spines / A-normal form

(= construction of syntax/proofs)

(67)

A logical framework for incremental type-checking

LF [Harper et al. 1992] provides a way to represent and validate syntax, rules and proofs by means of a typedλ-calculus. But we need a little bit more:

. . .

letu = pair y z : is nil (conj A B)in letv = app t u : is nil Cin . . .

1. definitions / explicit substitutions

2. type annotations on application spines 3. fully applied constants / η-long NF

4. Naming of all application spines / A-normal form

(= construction of syntax/proofs)

(68)

A logical framework for incremental type-checking

LF [Harper et al. 1992] provides a way to represent and validate syntax, rules and proofs by means of a typedλ-calculus. But we need a little bit more:

. . .

letu = pair y z : is nil (conj A B)in letv = app t u : is nil Cin . . .

1. definitions / explicit substitutions 2. type annotations on application spines

3. fully applied constants / η-long NF

4. Naming of all application spines / A-normal form

(= construction of syntax/proofs)

(69)

A logical framework for incremental type-checking

LF [Harper et al. 1992] provides a way to represent and validate syntax, rules and proofs by means of a typedλ-calculus. But we need a little bit more:

. . .

letu =pair y z: is nil (conj A B)in letv = app t u : is nil Cin . . .

1. definitions / explicit substitutions 2. type annotations on application spines 3. fully applied constants / η-long NF

4. Naming of all application spines / A-normal form

(= construction of syntax/proofs)

(70)

A logical framework for incremental type-checking

LF [Harper et al. 1992] provides a way to represent and validate syntax, rules and proofs by means of a typedλ-calculus. But we need a little bit more:

. . .

letu= pair y z : is nil (conj A B)in letv= app t u : is nil Cin . . .

1. definitions / explicit substitutions 2. type annotations on application spines 3. fully applied constants / η-long NF

4. Naming of all application spines / A-normal form

(= construction of syntax/proofs)

(71)

Positionality

R=

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

w

I Expose the headof the term

(λx.λy.T ) U V

I Abstract from the positions of the binders

(from inside and from outside)

(72)

Positionality

R=

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

w

I Expose the headof the term

(λx.λy.T ) U V

I Abstract from the positions of the binders

(from inside and from outside)

(73)

Positionality

R=

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

w

I Expose the headof the term

(λx.λy.T ) U V

I Abstract from the positions of the binders

(from inside and from outside)

(74)

Positionality

R=

let x = ... : is (cons (conj A B) nil ) Cin let y = ... : is nil Ain

let z = ... : is nil Bin

let t = lam (conj A B) x : is nil ( arr (conj A B) C)in let u = pair y z : is nil (conj A B)in

let v = app t u : is nil Cin let w = commit v w1 : versionin

w

I Expose the headof the term

(λx.λy.T ) U V

I Abstract from the positions of the binders

(from inside and from outside)

(75)

Menu

The big picture Our approach

Why not memoization?

A popular storage model for repositories Logical framework

Positionality The language

From LF to NLF

NLF: Syntax, typing, reduction Architecture

(76)

Presentation (of the ongoing formalization)

I alternative syntax for LF

I a datastructure of LF derivations

I the repository storage model

Motto: Take control of the environment

λLF

LJ-style annotation

−−−−−−−−−−−→ XLF

heads exposed forget positions

−−−−−−−−−−−→ NLF

(77)

From LF to XLF

K ::= ΠxA·K | ∗ A ::= ΠxA·A |A t|a

t ::= λxA·t |letx=t in t|t t |x |c Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(78)

From LF to XLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l]|a[l]

t ::= λxA·t |letx=t in t|t[l]|x[l]|c[l]

l ::= · |t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(79)

From LF to XLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t |letx=t in t|t[l] :A |x[l] :A |c[l] :A l ::= · |t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(80)

From LF to XLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t |letx=t in t|t[l] :A |x[l] :A |c[l] :A l ::= · |t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(81)

From LF to XLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t |letx=t in t|t[l] :A |x[l] :A |c[l] :A l ::= · |t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(82)

From LF to XLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t |letx=t in t|t[l] :A |x[l] :A |c[l] :A l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(83)

From LF to XLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t |letx=t in t|t[l] :A |x[l] :A |c[l] :A l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from standardλLF with definitions

I sequent calculus-like applications (¯λ)

I type annotations on application spines

I named arguments

(84)

XLF: Properties

I LJ-style application

I type annotation on application spines

I named arguments (labels) Lemma (Conservativity)

I Γ`LF K kind iff |Γ| `XLF|K| kind

I Γ`LF A type iff |Γ| `XLF|A|type

I Γ`LF t:A iff |Γ| `XLF|t|:|A|

(85)

From XLF to NLF

K ::= ΠxA·K | ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t |letx=t in t|t[l] :A |x[l] :A |c[l] :A l ::= · | x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(86)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |A[l] :K |a[l] :K

t ::= λxA·t|let x=tin t |t[l] :A|x[l] :A|c[l] :A l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(87)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |hA

hA ::= A[l] :K |a[l] :K

t ::= λxA·t|let x=tin t |t[l] :A|x[l] :A|c[l] :A l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(88)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |hA

hA ::= A[l] :K |a[l] :K

t ::= λxA·t|let x=tin t |ht

ht ::= t[l] :A |x[l] :A |c[l] :A l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(89)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |hA

hA ::= A[l] :hK |a[l] :hK

t ::= λxA·t|let x=tin t |ht

ht ::= t[l] :A |x[l] :A |c[l] :A l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(90)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |hA

hA ::= A[l] :hK |a[l] :hK

t ::= λxA·t|let x=tin t |ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(91)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |hA

hA ::= A[l] :hK |a[l] :hK

t ::= λxA·t|let x=tin t |ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

enforceη-long forms by annotating with heads

I factorize binders and environments

I abstract over environment datastructure (maps)

(92)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗

A ::= ΠxA·A |hA

hA ::= A[l] :hK |a[l] :hK

t ::= Γ`ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I abstract over environment datastructure (maps)

(93)

From XLF to NLF

K ::= ΠxA·K |hK

hK ::= ∗ A ::= Γ`hA

hA ::= A[l] :hK |a[l] :hK t ::= Γ`ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

enforceη-long forms by annotating with heads

I abstract over environment datastructure (maps)

(94)

From XLF to NLF

K ::= Γ`hk hK ::= ∗

A ::= Γ`hA

hA ::= A[l] :hK |a[l] :hK t ::= Γ`ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= · |x=t;l

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

I abstract over environment datastructure (maps)

(95)

From XLF to NLF

K ::= Γ`hk hK ::= ∗

A ::= Γ`hA

hA ::= A[l] :hK |a[l] :hK t ::= Γ`ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= Γ

Γ ::= · |Γ [x:A] |Γ [x=t]

Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

enforceη-long forms by annotating with heads

I abstract over environment datastructure (maps)

(96)

From XLF to NLF

K ::= Γ`hk hK ::= ∗

A ::= Γ`hA

hA ::= A[l] :hK |a[l] :hK t ::= Γ`ht

ht ::= t[l] :hA |x[l] :hA|c[l] :hA l ::= Γ

Γ : x7→([x:A] | [x=t]) Σ ::= · |Σ [c:A] |Σ [a:K]

I start from XLF

I isolate heads (non-binders)

I enforceη-long forms by annotating with heads

(97)

NLF

Syntax

K ::= Γ kind A ::= Γ`hA type hA ::= aΓ

t ::= Γ`ht:hA ht ::= tΓ |x Γ|c Γ

Γ : x7→([x:a] | [x=t])

Judgements

I Γ kind

I Γ`hAtype

(98)

NLF

Syntax

K ::= Γ kind A ::= Γ`hA type hA ::= aΓ

t ::= Γ`ht:hA ht ::= tΓ |x Γ|c Γ

Γ : x7→([x:a] | [x=t])

Judgements

I K

I A

(99)

NLF

Syntax

K ::= Γ kind A ::= Γ`hA type hA ::= aΓ

t ::= Γ`ht:hA ht ::= tΓ |x Γ|c Γ

Γ : x7→([x:a] | [x=t])

Judgements

I K wf

I A wf

(100)

NLF

Notations

I “hA” for “`hA

I “hA” for “∅ `hA type”

I “a” for “a∅”

Example

λfA→B·λxA·f x: (A→B)→A→B ≡ [f : [a:A]`B type] [x:A]`f [a=x] :B

(101)

Some more examples

A: ∅ kind

≡ ∗

vec: [len:N]kind

N→ ∗

nil : `vec [len= `0 :N]type

vec0 :

cons: [l:N] [hd:A] [tl: `vec [len= ` l:N]type]` vec [len= `s [n= `l:N] :N]type

ΠlN·AΠtlvec l·vec(s l:N) :

f ill : [n:N]`vec [len= `n:N]type

ΠnN·(vec n:∗)

empty : [e:vec [len= 0]]kind

vec0→ ∗

(102)

Environments

. . . double as labeleddirected acyclic graphsof dependencies:

Definition (environment)

Γ = (V, E) directed acyclic where:

I V ⊆ X ×(t]A) and

I (x, y)∈E (x depends ony) if y∈FV(Γ(x)) Definition (lookup)

Γ(x) :A if (x, A)∈E Γ(x) =t if (x, t)∈E Definition (bind)

Γ [x:A] = (V ∪(x, A), E∪ {(x, y) |y∈FV(A)}) Γ [x=t] = (V ∪(x, A), E∪ {(x, y) |y∈FV(t)})

(103)

Environments

. . . double as labeleddirected acyclic graphsof dependencies:

Definition (decls, defs)

decls(Γ) = [x1, . . . , xn] s.t. Γ(xi) :Ai topologically sortedwrt. Γ defs(Γ) = [x1, . . . , xn] s.t. Γ(xi) =ti topologically sorted wrt. Γ Definition (merge)

Γ·∆ = Γ∪∆ s.t.

I if Γ(x) :A and Γ(x) =tthen Γ·∆(x) =t

I undefined otherwise

Références

Documents relatifs

The effect of the act is that it is grounded that its content p holds for the speaker: he has expressed a kind of strong commitment (an assertion for W&K) on p in the sense that

Following the standard specification paradigm in Constructive Type Theory, we define lock types using introduction, elimination, and equality rules.. Correspondingly, we introduce

 It is easier not to be in conflict than to be in conflict. The former may mean that the agents are not even interacting. The latter supposes that the agents are within

We take the conjunction of the formulas identified in step 2 and we ma- nipulate it to transform it in the equivalent simplified Conjunctive Nor- mal Form (CNF). We label

The forced experiment with idealized Rockies and idealized Laurentide Ice Sheet has a less intense North Atlantic storm- track activity than the forced experiment with idealized

The key points were to consider an observational semantics with multiple interpretations and the understanding of the Nelson-Oppen theory combina- tion procedure and its followers as

Different methods used to measure anisotropic flow are affected by nonflow effects in different ways and are used in this analysis to evaluate the systematic uncertainty of

On introduit alors la théorie de la déformation partiellement imposée (DPI) ou Taylor relaxé.. Il faut obligatoirement introduire du glissement pour que la texture