• 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!
94
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

June 2011

INRIA – Gallium

(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:

separate compilation

dependency management

version control on the scripts

interactive toplevel with global rollback (Coq)

. . . ad-hoc tools, code duplication, hacks. . .

Examples

diff’s language-specific options, lines of context. . .

git’s merge heuristics

ocamldepvs. ocamlmodule system

coqtop’s rigidity

(6)

Incrementality in programming & proof languages

Q :

Do you spend more timewritingcode oreditingcode?

Today, we use:

separate compilation

dependency management

version control on the scripts

interactive toplevel with global rollback (Coq) . . . ad-hoc tools, code duplication, hacks. . .

Examples

diff’s language-specific options, lines of context. . .

git’s merge heuristics

ocamldepvs. ocamlmodule system

coqtop’s rigidity

(7)

In an ideal world. . .

Edition should be incrementally communicated to the tool

The impact of changes visible “in real time”

No need for separate compilation, dependency management. . .

Types are good witnesses of this impact

Applications

non-(linear|batch) user interaction

typed version control systems

type-directed programming

tactic languages

(8)

In an ideal world. . .

Edition should be incrementally communicated to the tool

The impact of changes visible “in real time”

No need for separate compilation, dependency management. . .

Types are good witnesses of this impact

Applications

non-(linear|batch) user interaction

typed version control systems

type-directed programming

tactic languages

(9)

In an ideal world. . .

Edition should be incrementally communicated to the tool

The impact of changes visible “in real time”

No need for separate compilation, dependency management. . .

Types are good witnesses of this impact

Applications

non-(linear|batch) user interaction

typed version control systems

type-directed programming

tactic languages

(10)

In this talk, we focus on. . .

. . . building a procedure to type-checklocal changes

What data structure for storing type derivations?

What language for expressing changes?

(11)

Menu

The big picture

Incremental type-checking Why not memoization?

Our approach

Two-passes type-checking The data-oriented way A metalanguage of repository

Tools

The LF logical framework Monadic LF

Typing by annotating

The typing/committing process

What does it do?

Example

Regaining version management

(12)

Menu

The big picture

Incremental type-checking Why not memoization?

Our approach

Two-passes type-checking The data-oriented way

A metalanguage of repository Tools

The LF logical framework Monadic LF

Typing by annotating

The typing/committing process

What does it do?

Example

Regaining version management

(13)

The big picture

version management script files

parsing type-checking

AST representation

Typing annotations

(14)

The big picture

version management

script files parsing

type-checking

AST representation

Typing annotations

(15)

The big picture

script files

version management

parsing type-checking

AST representation

Typing annotations

(16)

The big picture

script files parsing

version management type-checking

AST representation

Typing annotations

(17)

The big picture

script files parsing

version management type-checking

AST representation

Typing annotations

(18)

The big picture

user interaction parsing

version management type-checking

AST representation

Typing annotations

(19)

The big picture

user interaction parsing

type-checking

version management

AST representation

Typing annotations

(20)

The big picture

user interaction parsing

incremental type-checking version management

AST representation

Typing annotations

(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

builds and checks the derivation (on the stack)

conscientiously discards it

(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!

More precisely

Given a well-typedR:repository and aδ :deltaand apply:repository→delta→derivation , an incremental type-checker

tc:repository→delta→bool decides ifapply(δ,R) is well-typed inO(|δ|).

(and notO(|apply(δ,R)|))

(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!

More precisely

Given a well-typedR:repository and aδ :deltaand apply:repository→delta→derivation , an incremental type-checker

tc:repository→delta→bool decides ifapply(δ,R) is well-typed inO(|δ|).

(and notO(|apply(δ,R)|))

(24)

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!

More precisely

Given a well-typedR:repository and aδ :deltaand apply:repository→delta→derivation , an incremental type-checker

tc:repository→delta→repository option decides ifapply(δ,R) is well-typed inO(|δ|).

(and notO(|apply(δ,R)|))

(25)

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!

from

to

(26)

Memoization maybe?

let rec check env t a = matcht with

| ... → ... false

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

matcht with

| ... → ... None

| ... → ... Some a

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(27)

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

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(28)

Memoization maybe?

Syntactically

+ lightweight, efficient implementation

+ repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(29)

Memoization maybe?

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(30)

Memoization maybe?

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(31)

Memoization maybe?

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(32)

Memoization maybe?

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(33)

Memoization maybe?

Syntactically

+ lightweight, efficient implementation + repository=table,delta=t

– syntactic comparison (no quotient on judgements)

What if I wante.g. weakening or permutation to be taken into account?

Semantically

– external to the type system (meta-cut)

What does it mean logically?

JΓ Γ`JwfΓ

Γ1`J1wfΓ2 . . . Γn−1[Jn−1]`JnwfΓn Γ1`JwfΓn[Jn][J]

– imperative (introduces a dissymmetry)

Mixes two goals: derivation synthesis &object reuse

(34)

Menu

The big picture

Incremental type-checking Why not memoization?

Our approach

Two-passes type-checking The data-oriented way A metalanguage of repository

Tools

The LF logical framework Monadic LF

Typing by annotating

The typing/committing process

What does it do?

Example

Regaining version management

(35)

Two-passes type-checking

ti = type inference = derivation delta synthesis tc = type checking = derivation delta checking

δ = program delta δLF = derivation delta

R = repository of derivations

Shift of trust: ti(complex, ad-hoc algorithm)→ tc (simple, generic kernel)

(36)

Two-passes type-checking

ti = type inference = derivation delta synthesis tc = type checking = derivation delta checking

δ = program delta δLF = derivation delta

R = repository of derivations

Shift of trust: ti(complex, ad-hoc algorithm)→ tc (simple, generic kernel)

(37)

A popular storage model for directories

/

/foo /bar

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

v1

(38)

A popular storage model for directories

/

/foo /bar

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

/

/bar

/bar/c'

v1

/foo

/foo/a /bar/b

(39)

A popular storage model for directories

/

/foo /bar

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

/

/bar

/bar/c'

v1

(40)

A popular storage model for directories

/

/foo /bar

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

/

/bar

/bar/c'

v1

v2

(41)

A popular storage model for directories

/

/foo /bar

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

/

/bar

99dcf1d 46f9c2 923ace3

c328e8f d54c809

6e4f99a

4244e8a

cf189a6

e33478f

/bar/c'

v1

v2

820e7ab

a85f0b77

(42)

A popular storage model for directories

/

/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

(43)

A popular storage model for directories

/

/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

(44)

A popular storage model for directories

The repositoryRis a pair (∆, x):

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

Operations

commit δ extend the database with Tree/Blob objects

add a Commit object

update head

checkout v follow v all the way to theBlobs diff v1 v2 follow simultaneously v1 and v2

if object names are equal, stop (content is equal)

otherwise continue . . .

(45)

A popular storage model for directories

The repositoryRis a pair (∆, x):

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

Invariants

∆ forms a DAG

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

I (y,Tree t)

I (z,Commit(t, v))

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

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

(46)

A popular storage model for directories

The repositoryRis a pair (∆, x):

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

Invariants

∆ forms a DAG

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

I (y,Tree t)

I (z,Commit(t, v))

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

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

Let’s do the same with proofs

(47)

A typed repository of proofs

v1 - - : ⊢ C

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

(48)

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

(49)

A typed repository of proofs

- - : ⊢ C v1

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

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

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

π₃' : ⊢B

(50)

A typed repository of proofs

- - : ⊢ C v1

v2 - - : ⊢ C

λ- : ⊢(A∧B)→C

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

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

π₃' : ⊢B

(51)

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

(52)

A typed repository of proofs

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

t=λa:AB·x:`ABC u= (y, z) : `AB

v=t u:`C

w=Commit(v, w1) :Version

(53)

A typed repository of proofs

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

t=λa:AB·x:`ABC u= (y, z) : `AB

v=t u:`C

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

(54)

A typed repository of proofs

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

t=λa:AB·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

(55)

A typed repository of proofs

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

t=λa:AB·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

(56)

A data-oriented notion of delta

A delta is a term twith variablesx, y, defined in the repository

A repositoryR is aflattened,annotatedterm with ahead

Incrementality by sharing common subterms

Invariants

R forms a DAG

Annotations are validwrt. proof rules

(57)

A data-oriented notion of delta

A delta is a term twith variablesx, y, defined in the repository

A repositoryR is aflattened,annotated term with ahead

Incrementality by sharing common subterms

Invariants

R forms a DAG

Annotations are validwrt. proof rules

(58)

A data-oriented notion of delta

A delta is a term twith variablesx, y, defined in the repository

A repositoryR is aflattened,annotated term with ahead

Incrementality by sharing common subterms

Invariants

R forms a DAG

Annotations are validwrt. proof rules

(59)

A data-oriented notion of delta

A delta is a term twith variablesx, y, defined in the repository

A repositoryR is aflattened,annotated term with ahead

Incrementality by sharing common subterms

Invariants

R forms a DAG

Annotations are validwrt. proof rules

(60)

Higher-order notion of delta

Problem

Proofs are higher-order objects by nature:

Example

We can’t allow sharing in `t:B without instantiating `x:A (scope escape)

(61)

Higher-order notion of delta

Solutions

“first-orderize” your logic (de Bruijn indices, Γ is a list. . . ) + we’re done

weakening, permutation, substitution etc. become explicit operations

delta application possibly has to rewrite the repository (lift) dull dull dull. . .

“let metahandle it” (the delta language) + known technique (HOAS)

+ implicit environments = weakening, permutation, substitution for free

have to add an instantiation operator

(62)

Higher-order notion of delta

Solution

A delta is a term twith variablesx, y and boxes [t]uy.n to jump over lambdas in the repository

(63)

Towards a metalanguage of proof repository

Repository language 1. name all proof steps

2. annote them by their judgement Delta language

1. address sub-proofs (variables) 2. instantiate lambdas (boxes) 3. check against R

(64)

Menu

The big picture

Incremental type-checking Why not memoization?

Our approach

Two-passes type-checking The data-oriented way

A metalanguage of repository Tools

The LF logical framework Monadic LF

Typing by annotating

The typing/committing process

What does it do?

Example

Regaining version management

(65)

A logical framework for incremental type-checking

LF [Harper et al. 1992] (a.k.a. λΠ) provides a meta-logicto represent and validate syntax, rules and proofs of anobject language, by means of a typedλ-calculus.

dependent types to express object-judgements signature to encode the object language

higher-order abstract syntax to easily manipulate hypothesis

Examples

[x:A] .. . t:B λx·t:AB

is-lam: ΠA, B:ty·Πt:tmtm· (Πx:tm·isx Ais(t x)B) is(lamA(λx·t x))(arrA B)

[x:N]

λx·x:NN

is-lam nat nat(λx·x) (λyz·z) :is(lam nat(λx·x)) (arr nat nat)

(66)

A logical framework for incremental type-checking

LF [Harper et al. 1992] (a.k.a. λΠ) provides a meta-logicto represent and validate syntax, rules and proofs of anobject language, by means of a typedλ-calculus.

dependent types to express object-judgements signature to encode the object language

higher-order abstract syntax to easily manipulate hypothesis Examples

[x:A]

.. . t:B λx·t:AB

is-lam: ΠA, B:ty·Πt:tmtm·

(Πx:tm·isx Ais(t x)B) is(lamA(λx·t x))(arrA B)

[x:N]

λx·x:NN

is-lam nat nat(λx·x) (λyz·z) :is(lam nat(λx·x)) (arr nat nat)

(67)

A logical framework for incremental type-checking

Syntax

K ::= Πx:A·K | ∗ A ::= Πx:A·A |a(l)

t ::= λx·t |x(l) |c(l) l ::= · |t, l

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

Judgements

Γ`ΣK

Γ`ΣA

Γ`Σt:A

Γ, A`Σ l:A

`Σ Γ`t:A Γ, BJx/tK`l:B

Γ,Πx:A·B` t, l:C Remarks

the spine-form, canonicalflavor (β and η-long normal)

substitution is hereditary (i.e. cut-admissibility / big-step reduction)

(68)

Naming of proof steps

Remark

In LF, proof step = term application spine Exampleis-lam nat nat (λx·x) (λyz·z)

Monadic Normal Form (MNF)

Program transformation, IR for FP compilers

Goal: sequentialize all computations by naming them (lets) t ::= λx·t|t(l) |x

l ::= · |t, l =⇒

t ::= ret v|let x=v(l) in t|v(l) l ::= · |v, l

v ::= x |λx·t Examples

f(g(x)) ∈/ MNF

λx·f(g(λy·y, x)) =⇒

ret (λx·leta=g(λy·y, x)in f(a))

(69)

Naming of proof steps

Remark

In LF, proof step = term application spine Exampleis-lam nat nat (λx·x) (λyz·z) Monadic Normal Form (MNF)

Program transformation, IR for FP compilers

Goal: sequentialize all computations by naming them (lets) t ::= λx·t|t(l)|x

l ::= · |t, l =⇒

t ::= retv |let x=v(l) in t|v(l) l ::= · |v, l

v ::= x |λx·t Examples

f(g(x)) ∈/ MNF

λx·f(g(λy·y, x)) =⇒

ret(λx·leta=g(λy·y, x)in f(a))

(70)

Naming of proof steps

Positionality inefficiency

Order of lets is irrelevant, we just want non-cyclicity and fast access.

let x=. . . in lety =. . .in

let z=. . .in ...

v(l)

=⇒

x=. . . y=. . . z=. . . ...

`v(l)

Non-positional monadic calculus

t ::= retv |σ`v(l) l ::= · |v, l

v ::= x|λx·t σ : x7→v(l)

(71)

Naming of proof steps

Positionality inefficiency

Order of lets is irrelevant, we just want non-cyclicity and fast access.

let x=. . . in lety =. . .in

let z=. . .in ...

v(l)

=⇒

x=. . . y=. . . z=. . . ...

`v(l)

Non-positional monadic calculus

t ::= retv |letx=v(l)in t |v(l) l ::= · |v, l

v ::= x|λx·t

(72)

Naming of proof steps

Positionality inefficiency

Order of lets is irrelevant, we just want non-cyclicity and fast access.

let x=. . . in lety =. . .in

let z=. . .in ...

v(l)

=⇒

x=. . . y=. . . z=. . . ...

`v(l)

Non-positional monadic calculus

t ::= retv |σ `v(l) l ::= · |v, l

v ::= x |λx·t σ ::= · |σ[x=v(l)]

(73)

Naming of proof steps

Positionality inefficiency

Order of lets is irrelevant, we just want non-cyclicity and fast access.

let x=. . . in lety =. . .in

let z=. . .in ...

v(l)

=⇒

x=. . . y=. . . z=. . . ...

`v(l)

Non-positional monadic calculus

t ::= retv |σ`v(l) l ::= · |v, l

v ::= x|λx·t σ : x7→v(l)

(74)

Monadic LF

K ::= Πx:A·K | ∗ A ::= Πx:A·A |σ`a(l)

t ::= retv |σ `v(l) h ::= x |c

l ::= · |v, l v ::= c|x |λx·t σ : x7→h(l)

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

Definition

· : LF→monadic LF One-pass, direct style version of [Danvy 2003]

(75)

Monadic LF

K ::= Πx:A·K | ∗ A ::= Πx:A·A |σ`a(l)

t ::= retv |σ `v(l) h ::= x |c

l ::= · |v, l v ::= c|x |λx·t σ : x7→h(l)

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

Definition

· : LF→monadic LF One-pass, direct style version of [Danvy 2003]

(76)

Monadic LF

K ::= Πx:A·K | ∗ A ::= Πx:A·A |σ`a(l)

t ::= σ`v h ::= x |c

l ::= · |v, l v ::= c|x |λx·t σ : x7→h(l)

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

Definition

· : LF→monadic LF One-pass, direct style version of [Danvy 2003]

(77)

Monadic LF

K ::= Πx:A·K | ∗ A ::= Πx:A·A |σ`a(l)

t ::= σ`v h ::= x |c

l ::= · |v, l v ::= c|x |λx·t σ : x7→h(l)

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

Definition

· : LF→monadic LF One-pass, direct style version of [Danvy 2003]

(78)

Type annotation

Remark

In LF, judgement annotation = type annotation Example

is-lam nat nat(λx·x) (λyz·z)

:is(lam nat (λx·x)) (arr nat nat)

K ::= Πx:A·K | ∗ A ::= Πx:A·A|σ `a(l) R ::= σ `v:a(l)

←−σ DAG, binds inv and l

h ::= x |a l ::= · |v, l

v ::= c |x |λx:A·R σ : x7→h(l) :a(l)

←−named implementation

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

(79)

Type annotation

Remark

In LF, judgement annotation = type annotation Example

is-lam nat nat(λx·x) (λyz·z)

:is(lam nat (λx·x)) (arr nat nat)

K ::= Πx:A·K | ∗ A ::= Πx:A·A|σ `a(l)

t ::= σ `v:a(l)

←− σ DAG, binds inv and l

h ::= x |a l ::= · |v, l

v ::= c |x |λx:A·t σ : x7→h(l) :a(l)

←− named implementation

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

(80)

The repository language

Remark

In LF, judgement annotation = type annotation Example

is-lam nat nat(λx·x) (λyz·z)

:is(lam nat (λx·x)) (arr nat nat)

K ::= Πx:A·K | ∗ A ::= Πx:A·A|σ `a(l) R ::= σ `v:a(l)

←− σ DAG, binds inv and l

h ::= x |a l ::= · |v, l

v ::= c |x |λx:A·R σ : x7→h(l) :a(l)

←− named implementation

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

(81)

The repository language

Remark

In LF, judgement annotation = type annotation Example

is-lam nat nat(λx·x) (λyz·z)

:is(lam nat (λx·x)) (arr nat nat)

K ::= Πx:A·K | ∗ A ::= Πx:A·A|σ `a(l)

R ::= σ `v:a(l) ←− σ DAG, binds inv and l h ::= x |a

l ::= · |v, l

v ::= c |x |λx:A·R σ : x7→h(l) :a(l)

←− named implementation

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

(82)

The repository language

Remark

In LF, judgement annotation = type annotation Example

is-lam nat nat(λx·x) (λyz·z)

:is(lam nat (λx·x)) (arr nat nat)

K ::= Πx:A·K | ∗ A ::= Πx:A·A|σ `a(l)

R ::= σ `v:a(l) ←− σ DAG, binds inv and l h ::= x |a

l ::= · |v, l

v ::= c |x |λx:A·R

σ : x7→h(l) :a(l) ←− named implementation Σ ::= · |Σ[c:A]|Σ[a:K]

(83)

The delta language

Syntax

K ::= Πx:A·K | ∗ A ::= Πx:A·A |a(l)

t ::= λx·t|x(l) |c(l) |[t]tx.n l ::= · |t, l

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

Judgements

R,Γ`K →K

R,Γ`A→A

R,Γ`t:A→t

R,Γ, A` l→l:A

` Σ→Σ Informally

R,Γ`Σ x⇒ Rmeans

“I am what x stands for, in Γ or inR (and produceR)”.

R,Γ`Σ [t]uy.n⇒ R0 means

“Variable y has the formc(v1. . . vn−1(λx· R00). . .) in R.

Make all variables in R00 in scope fort, taking ufor x.

In this new scope, twill produce R0

(84)

The typing/committing process

R, Γ ` t : A → t

What does it do?

puts tin non-pos. MNF (O(t))

type-checks twrt. R and

returns ti.e. tannotated with types (O(t))

(85)

Typing by annotating

partial translation: monadic LF → annotated monadic LF VLam

R, Γ[x : A] ` t : B → t

R, Γ ` λx · t : Πx : A · B → λx : A · t

(86)

Typing by annotating

partial translation: monadic LF → annotated monadic LF HVar

Γ(x) : A or σ(x) : A

(σ ` v), Γ ` x → A

(87)

Typing by annotating

partial translation: monadic LF → annotated monadic LF

LCons

R, Γ ` v : A → v R, Γ, B J x/v K ` l → l : a(l)

R, Γ, Πx : A · B ` v, l → v, l : a(l)

(88)

Typing by annotating

partial translation: monadic LF → annotated monadic LF

OBox

R|

p

= λx : B · R

0

R, Γ ` u : B → (σ ` h : a(l)) R

0

∪ σ[x = h : a(l)], Γ ` t : A → t

R, Γ ` [t]

up

: A → t

(89)

Typing by annotating

partial translation: monadic LF → annotated monadic LF

(Πx:A·B)Jz/vK= Πx:AJz/vK·BJz/vK (σ`a(l))Jz/vK=σJz/vK`a(lJz/vK)

(σ[y =x(l) :a(m)])Jz/vK= (σJz/vK)[y=x(lJz/vK) :a(mJz/vK)]

(σ[y =z(l) :a(m)])Jz/vK=redyσ(v, l) redyσ(h:a(l),·) =σ[y=h:a(l)]

redyσ(λx:A·t,(v, l)) =redyσ∪ρ(w, l) if tJx/vK= (ρ`w) ...

(90)

Properties of the translation

Work in progress. . . Theorem (Soundness)

ifΓ`t:A then `Γ→Γ and (· ` ),Γ` A →A and (· ` ),Γ`t :A→t

Definition (Checkout)

Let· be the back-translation function of a repository into an LF term.

Theorem (Completeness)

if(· ` ),Γ`t :A→tthen Γ`t:A Theorem (Substitution)

If R,Γ` u:B→(σ`y:B) and Γ[x:B]∆`t:A then (σ`y:B),Γ∆{x/y} `t{x/y}:B{x/y} → R0

(91)

Example

Signature

A B C D:∗

a: (D→B)→C →A b b0 :C→B

c:D→C d:D

Terms

t1 = a(λx·b(c(x)), c(d)) R1 = [v=c(d) :C]

[u=a(λx:D·[w=c(x) :C][w0=b(w) :B]`w0 :B, v) :A]

`u:A t2 = a(λy·[b0(w)]x1y) R2 = [v=c(d) :C]

[u=a(λy:D·[x=y][w=c(x) :C][w0=b(w) :B]`w0 :B, v) :A]

`u:A

(92)

Regaining version management

Just add to the signature Σ:

Version:∗ Commit0:Version

Commit: Πt:tm·is(t,unit)→Version→Version Commit t

if R=σ `v:Version and R,· `Σt:is(p,unit)⇒(ρ`k) then

ρ[x=Commit(p, k, v)]`x:Version is the new repository

(93)

Further work

metatheory of annotated monadic LF

from terms to derivations (ti)

diff on terms

mimick other operations from VCS (Merge)

Thank you!

(94)

Further work

metatheory of annotated monadic LF

from terms to derivations (ti)

diff on terms

mimick other operations from VCS (Merge)

Thank you!

Références

Documents relatifs

Moreover as suggested by Rahman/Ibal (2017) if we study cooperation at the play-level, many cases we do not need to endow the notion of inference with

Our default case decision policy seems to lead to a deterministic behavior, where C manages to reach the right lane ahead of vehicle B while A has to brake to avoid a collision

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

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

We define a class of certifying distributed algorithm that terminate and verify their distributed input-output pair at runtime by a distributed witness such that the

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

“Thing” class of the retailer, manufacturer and reference ontologies and a set of rules that aim to represent the mappings between the concepts were defined.These

In fact, it states that, if a given expression holds in a certain state and is supposed to keep holding after some expected events have happened, then checking this expression