SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Continuation calculus
Bram Geron1 Herman Geuvers1,2
1Eindhoven University of Technology
2Radboud University Nijmegen
Term Rewriting Seminar, May 2013
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 1 / 22
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 2 / 22
First look Rules, names, variables, terms
CC is a constrained term rewriting system
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact.4)
Rules
One definition per name
(max)
No pattern matching
Only head reduction
Consequences
Deterministic
Simple operational semantics
Suitable for modeling
continuations, hence exceptions
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
First look Rules, names, variables, terms
CC is a constrained term rewriting system
rule
Comp
name
(constant)
.f .g.x
variables
def
−→ f .(g.x)
Comp.AddOne.Fact.4
term
→ AddOne.(Fact.4)
term
Rules
One definition per name
(max)
No pattern matching
Only head reduction
Consequences
Deterministic
Simple operational semantics
Suitable for modeling
continuations, hence exceptions
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
First look Rules, names, variables, terms
CC is a constrained term rewriting system
rule
Comp
name
(constant)
.f .g.x
variables
def
−→ f .(g.x)
Comp.AddOne.Fact.4
term
→ AddOne.(Fact.4)
term
Rules
One definition per name
(max)
No pattern matching
Only head reduction
Consequences
Deterministic
Simple operational semantics
Suitable for modeling
continuations, hence exceptions
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.f .g.x
def
−→ f .(g.x)
Comp.AddOne.Fact.4 → AddOne.(Fact).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.r.f .g.x
def
−→ g.(f .r).x
Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
First look Head reduction: continuation passing style
Functions fill in the result in their continuation parameter
Comp.r.f .g.x
def
−→ g.(f .r).x
Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4
Realistic names:
Fact.r.x r.x!
AddOne.r.x r.(x +1)
Fact.(AddOne.r).4 AddOne.r.24
r.25
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
Definition
Definitions
There is an infinite set of names, indicated by a capital.
A term is either a name, or two terms combined by a dot.
We write a.b.c as shorthand for (a.b).c.
A program P consists of a set of rules, of the form
Name.variable.··· .variable
def
−→ term over those variables
That rule defines that name.
Each rule defines a different name.
If “N.x1 .··· .xk
def
−→ r” ∈ P, then we reduce N.t → r[t/x].
Term N.x1.··· .xl for l = k does not reduce at all.
There is only head reduction.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
Definition
Definitions
There is an infinite set of names, indicated by a capital.
A term is either a name, or two terms combined by a dot.
We write a.b.c as shorthand for (a.b).c.
A program P consists of a set of rules, of the form
Name.variable.··· .variable
def
−→ term over those variables
That rule defines that name.
Each rule defines a different name.
If “N.x1 .··· .xk
def
−→ r” ∈ P, then we reduce N.t → r[t/x].
Term N.x1.··· .xl for l = k does not reduce at all.
There is only head reduction.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
Definition
Definitions
There is an infinite set of names, indicated by a capital.
A term is either a name, or two terms combined by a dot.
We write a.b.c as shorthand for (a.b).c.
A program P consists of a set of rules, of the form
Name.variable.··· .variable
def
−→ term over those variables
That rule defines that name.
Each rule defines a different name.
If “N.x1 .··· .xk
def
−→ r” ∈ P, then we reduce N.t → r[t/x].
Term N.x1.··· .xl for l = k does not reduce at all.
There is only head reduction.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
Long-term goal
Long-term goal
Formally modeling programming languages
Hopefully as a base for better languages
Operational semantics
Running time: #steps ∼ seconds CPU time
Warning: some unsubstantiated claims
Compositional
Facilitates proving properties
Deterministic by nature
Works with continuations
Explained later
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
Long-term goal
Long-term goal
Formally modeling programming languages
Hopefully as a base for better languages
Operational semantics
Running time: #steps ∼ seconds CPU time
Warning: some unsubstantiated claims
Compositional
Facilitates proving properties
Deterministic by nature
Works with continuations
Explained later
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
Interfaces, not pattern matching
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 7 / 22
Interfaces, not pattern matching
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 8 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero))
→ Add.r.(S.Zero).Zero
→ Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero))
→ Add.r.(S.Zero).Zero
→ Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
What can we feed to Add?
Zero
S.(··· .(S.Zero)···)
Something else?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
Interfaces, not pattern matching
Natural numbers
Slightly similar to lambda calculus
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
What can we feed to Add?
Zero
S.(··· .(S.Zero)···)
Something else? Yes!
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
Interfaces, not pattern matching
Natural numbers
Compatible naturals
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
We define when a term t represents natural number n.
1 t represents 0 if ∀z,s : t.z.s z
Informally: t “behaves the same as” Zero
2 t represents n +1 if ∀z,s : t.z.s s.q, and q represents n
Informally: t “behaves the same as” S.q
With this, we can define LazyFact such that LazyFact.x represents (x!).
(Omitted.)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
Interfaces, not pattern matching
Natural numbers
Compatible naturals
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
With this, we can define LazyFact such that LazyFact.x represents (x!).
(Omitted.)
Add.r.Zero.(LazyFact.(S.Zero)) → LazyFact.(S.Zero).(r.Zero).(Add.r.(S.Zero))
Add.r.(S.Zero).Zero
→ Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero)))
→ r.(S.Zero)
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
Interfaces, not pattern matching
Natural numbers
Compatible naturals
Zero.z.s
def
−→ z
S.x.z.s
def
−→ s.x
Add.r.x.y
def
−→ y.(r.x).(Add.r.(S.x))
Algorithm:
x +0 = x
x +S(y) = S(x)+y
With this, we can define LazyFact such that LazyFact.x represents (x!).
(Omitted.)
Add.r.Zero.(LazyFact.(S.Zero)) r.(S.Zero)
Two types of function names
Call-by-value / eager: calculate result, fill in in continuation
Call-by-name / lazy: compatible with Sn.Zero but delayed
computation
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
The importance of head reduction
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 12 / 22
The importance of head reduction
Outline
1 First look
2 Definition
3 Long-term goal
4 Interfaces, not pattern matching
5 The importance of head reduction
6 Relation to lambda calculus
7 Conclusion
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 13 / 22
The importance of head reduction
Operational semantics
Lambda calculus (normal order)
Reduction using two instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
as presented in [Levy(2001)]
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 14 / 22
The importance of head reduction
Back to modeling programs
Lambda calculus
λx.+ (f x) (g x)
M N Push N on stack,
continue in M
λx.M Pop N off stack,
continue in M[N/x]
Programming language
fun x → (f x) + (g x)
M N Apply function object
to argument
fun x → M Make function object
In “real languages”, functions throw exceptions and have other side effects.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
The importance of head reduction
Back to modeling programs
Lambda calculus
λx.+ (f x) (g x)
M N Push N on stack,
continue in M
λx.M Pop N off stack,
continue in M[N/x]
Programming language
fun x → (f x) + (g x)
throws exception
now what?
M N Apply function object
to argument
fun x → M Make function object
In “real languages”, functions throw exceptions and have other side effects.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
The importance of head reduction
Operational semantics
Computational models with control
Lambda calculus + continuations (λC)
Reduction using four instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
A M Empty the stack, continue in M
C M Empty the stack, continue in M (λx.S x)
where function S ‘restores’ the previous stack
(details omitted)
Can model exception-like facilities
CPS transformation to transform λC terms to λ terms
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 16 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
What is this subset, really?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
What is this subset, really?
Can we describe it?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
CPS transformation
λC
CPS transformation
−−−−−−−−−−−→ subset of λ, makes minimal use of stack
Two calculi in action:
λC calculus: M N, λx.M, A M, C M
Expressive
Subset of λ calculus: M N, λx.M
Simpler
What is this subset, really?
Can we describe it?
An elegant model of computation, perhaps?
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
The importance of head reduction
Lambda calculus vs. continuation calculus
λC
Four instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
A M Empty the stack, continue in M
C M Empty the stack, continue in M (λx.S x)
where function S ‘restores’ the stack
Continuation calculus
One instruction on the top level, using program P
n.t1.··· .tk Empty the stack, continue in r[t/x]
if n.x1 .··· .xk
def
−→ r ∈ P
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
The importance of head reduction
Lambda calculus vs. continuation calculus
λC
Four instructions on the top level
M N Push N on stack, continue in M
λx.M Pop N off stack, continue in M[N/x]
A M Empty the stack, continue in M
C M Empty the stack, continue in M (λx.S x)
where function S ‘restores’ the stack
Continuation calculus
One instruction on the top level, using program P
n.t1.··· .tk Empty the stack, continue in r[t/x]
if n.x1 .··· .xk
def
−→ r ∈ P
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
The importance of head reduction
Continuation calculus
Continuation calculus
One instruction on the top level, using program P
n.t1.··· .tk Continue in r[t/x]
if n.x1 .··· .xk
def
−→ r ∈ P
No stack needed, because
n.t1.··· .tl does not reduce for l = k.
Subterms are not reduced
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 19 / 22
Relation to lambda calculus
Relation to lambda calculus
λ,λC
CPS transformation
−−−−−−−−−−−→ subset of λ
subset of λ
λx to rules∗
−−−−−−−−−−−−−−−−−−−−−−
unfold†
rules to λx
CC
∗ λx to rules: involves a supercombinator transformation
† Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references
Catchphrase
CC is more limited than λ,
thus more suitable to model continuations
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
Relation to lambda calculus
Relation to lambda calculus
λ,λC
CPS transformation
−−−−−−−−−−−→ subset of λ
subset of λ
λx to rules∗
−−−−−−−−−−−−−−−−−−−−−−
unfold†
rules to λx
CC
∗ λx to rules: involves a supercombinator transformation
† Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references
Catchphrase
CC is more limited than λ,
thus more suitable to model continuations
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
Conclusion
Conclusion
CC is a constrained term rewriting system
CC is deterministic
Only head reduction
As a consequence,
Suitable for control with continuations (exceptions)
CC is similar to a subset of lambda calculus
Allows both eager and lazy function terms
call-by-value vs. call-by-name
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 21 / 22
Appendix
Bibliography
P.B. Levy.
Call-by-push-value.
PhD thesis, Queen Mary, University of London, 2001.
Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 22 / 22

Contenu connexe

Tendances

International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)inventionjournals
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...Federico Cerutti
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...Federico Cerutti
 
Conflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revisionConflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revisionstellaseremetaki
 
Argumentation in Artificial Intelligence
Argumentation in Artificial IntelligenceArgumentation in Artificial Intelligence
Argumentation in Artificial IntelligenceFederico Cerutti
 
Bodecoban ngobaochau
Bodecoban ngobaochauBodecoban ngobaochau
Bodecoban ngobaochauDuong Tran
 
5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)Jan Plaza
 
Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Omnia A. Abdullah
 
5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.Jan Plaza
 
Darmon Points: an overview
Darmon Points: an overviewDarmon Points: an overview
Darmon Points: an overviewmmasdeu
 
Fundamental Theorem of Calculus
Fundamental Theorem of CalculusFundamental Theorem of Calculus
Fundamental Theorem of Calculusgizemk
 
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)
D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)Bluewworksblue
 
Truth as a logical connective
Truth as a logical connectiveTruth as a logical connective
Truth as a logical connectiveShunsuke Yatabe
 
Geometry Section 4-3
Geometry Section 4-3Geometry Section 4-3
Geometry Section 4-3Jimbo Lamb
 
Quantum optical models in noncommutative spaces
Quantum optical models in noncommutative spacesQuantum optical models in noncommutative spaces
Quantum optical models in noncommutative spacesSanjib Dey
 

Tendances (19)

10.1.1.226.4381
10.1.1.226.438110.1.1.226.4381
10.1.1.226.4381
 
International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Right m...
 
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
Argumentation in Artificial Intelligence: 20 years after Dung's work. Left ma...
 
Conflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revisionConflicts between relevance-sensitive revision
Conflicts between relevance-sensitive revision
 
Argumentation in Artificial Intelligence
Argumentation in Artificial IntelligenceArgumentation in Artificial Intelligence
Argumentation in Artificial Intelligence
 
Bodecoban ngobaochau
Bodecoban ngobaochauBodecoban ngobaochau
Bodecoban ngobaochau
 
5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)
 
AI Lesson 14
AI Lesson 14AI Lesson 14
AI Lesson 14
 
Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Discrete Mathematics - All chapters
Discrete Mathematics - All chapters
 
5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.
 
Darmon Points: an overview
Darmon Points: an overviewDarmon Points: an overview
Darmon Points: an overview
 
Chap05
Chap05Chap05
Chap05
 
Fundamental Theorem of Calculus
Fundamental Theorem of CalculusFundamental Theorem of Calculus
Fundamental Theorem of Calculus
 
AI Lesson 15
AI Lesson 15AI Lesson 15
AI Lesson 15
 
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)
D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)D. h. fremlin   measure theory, volume 5, part 1   (2000, torres fremlin)
D. h. fremlin measure theory, volume 5, part 1 (2000, torres fremlin)
 
Truth as a logical connective
Truth as a logical connectiveTruth as a logical connective
Truth as a logical connective
 
Geometry Section 4-3
Geometry Section 4-3Geometry Section 4-3
Geometry Section 4-3
 
Quantum optical models in noncommutative spaces
Quantum optical models in noncommutative spacesQuantum optical models in noncommutative spaces
Quantum optical models in noncommutative spaces
 

Similaire à Continuation calculus at Term Rewriting Seminar

2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting PosterChelsea Battell
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
Applications of partial differentiation
Applications of partial differentiationApplications of partial differentiation
Applications of partial differentiationVaibhav Tandel
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus AhsanIrshad8
 
Testing Forest-Isomorphism in the Adjacency List Model
Testing Forest-Isomorphismin the Adjacency List ModelTesting Forest-Isomorphismin the Adjacency List Model
Testing Forest-Isomorphism in the Adjacency List Modelirrrrr
 
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Kenshi Abe
 
Data Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression ModelsData Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression ModelsColleen Farrelly
 
Optimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesOptimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesEmmanuel Hadoux
 
Reciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical SingularitiesReciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical SingularitiesLukasz Obara
 
Fixed point result in menger space with ea property
Fixed point result in menger space with ea propertyFixed point result in menger space with ea property
Fixed point result in menger space with ea propertyAlexander Decker
 
Prime numbers boundary
Prime numbers boundary Prime numbers boundary
Prime numbers boundary Camilo Ulloa
 
The Chase in Database Theory
The Chase in Database TheoryThe Chase in Database Theory
The Chase in Database TheoryJan Hidders
 
Darmon Points for fields of mixed signature
Darmon Points for fields of mixed signatureDarmon Points for fields of mixed signature
Darmon Points for fields of mixed signaturemmasdeu
 
A Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC LearningA Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC Learningdhruvgairola
 

Similaire à Continuation calculus at Term Rewriting Seminar (20)

Pl vol1
Pl vol1Pl vol1
Pl vol1
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Applications of partial differentiation
Applications of partial differentiationApplications of partial differentiation
Applications of partial differentiation
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
 
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
 
Testing Forest-Isomorphism in the Adjacency List Model
Testing Forest-Isomorphismin the Adjacency List ModelTesting Forest-Isomorphismin the Adjacency List Model
Testing Forest-Isomorphism in the Adjacency List Model
 
Big o
Big oBig o
Big o
 
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
Competitive Multi-agent Inverse Reinforcement Learning with Sub-optimal Demon...
 
Data Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression ModelsData Science Meetup: DGLARS and Homotopy LASSO for Regression Models
Data Science Meetup: DGLARS and Homotopy LASSO for Regression Models
 
Optimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesOptimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processes
 
Reciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical SingularitiesReciprocity Law For Flat Conformal Metrics With Conical Singularities
Reciprocity Law For Flat Conformal Metrics With Conical Singularities
 
H-MLQ
H-MLQH-MLQ
H-MLQ
 
Fixed point result in menger space with ea property
Fixed point result in menger space with ea propertyFixed point result in menger space with ea property
Fixed point result in menger space with ea property
 
Prime numbers boundary
Prime numbers boundary Prime numbers boundary
Prime numbers boundary
 
The Chase in Database Theory
The Chase in Database TheoryThe Chase in Database Theory
The Chase in Database Theory
 
04_AJMS_254_19.pdf
04_AJMS_254_19.pdf04_AJMS_254_19.pdf
04_AJMS_254_19.pdf
 
Darmon Points for fields of mixed signature
Darmon Points for fields of mixed signatureDarmon Points for fields of mixed signature
Darmon Points for fields of mixed signature
 
A Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC LearningA Theory of the Learnable; PAC Learning
A Theory of the Learnable; PAC Learning
 

Dernier

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Dernier (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Continuation calculus at Term Rewriting Seminar

  • 1. Continuation calculus Bram Geron1 Herman Geuvers1,2 1Eindhoven University of Technology 2Radboud University Nijmegen Term Rewriting Seminar, May 2013 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 1 / 22
  • 2. Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 2 / 22
  • 3. First look Rules, names, variables, terms CC is a constrained term rewriting system Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact.4) Rules One definition per name (max) No pattern matching Only head reduction Consequences Deterministic Simple operational semantics Suitable for modeling continuations, hence exceptions Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
  • 4. First look Rules, names, variables, terms CC is a constrained term rewriting system rule Comp name (constant) .f .g.x variables def −→ f .(g.x) Comp.AddOne.Fact.4 term → AddOne.(Fact.4) term Rules One definition per name (max) No pattern matching Only head reduction Consequences Deterministic Simple operational semantics Suitable for modeling continuations, hence exceptions Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
  • 5. First look Rules, names, variables, terms CC is a constrained term rewriting system rule Comp name (constant) .f .g.x variables def −→ f .(g.x) Comp.AddOne.Fact.4 term → AddOne.(Fact.4) term Rules One definition per name (max) No pattern matching Only head reduction Consequences Deterministic Simple operational semantics Suitable for modeling continuations, hence exceptions Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 3 / 22
  • 6. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 7. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 8. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.f .g.x def −→ f .(g.x) Comp.AddOne.Fact.4 → AddOne.(Fact).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 9. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.r.f .g.x def −→ g.(f .r).x Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 10. First look Head reduction: continuation passing style Functions fill in the result in their continuation parameter Comp.r.f .g.x def −→ g.(f .r).x Comp.r.AddOne.Fact.4 → Fact.(AddOne.r).4 Realistic names: Fact.r.x r.x! AddOne.r.x r.(x +1) Fact.(AddOne.r).4 AddOne.r.24 r.25 Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 4 / 22
  • 11. Definition Definitions There is an infinite set of names, indicated by a capital. A term is either a name, or two terms combined by a dot. We write a.b.c as shorthand for (a.b).c. A program P consists of a set of rules, of the form Name.variable.··· .variable def −→ term over those variables That rule defines that name. Each rule defines a different name. If “N.x1 .··· .xk def −→ r” ∈ P, then we reduce N.t → r[t/x]. Term N.x1.··· .xl for l = k does not reduce at all. There is only head reduction. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
  • 12. Definition Definitions There is an infinite set of names, indicated by a capital. A term is either a name, or two terms combined by a dot. We write a.b.c as shorthand for (a.b).c. A program P consists of a set of rules, of the form Name.variable.··· .variable def −→ term over those variables That rule defines that name. Each rule defines a different name. If “N.x1 .··· .xk def −→ r” ∈ P, then we reduce N.t → r[t/x]. Term N.x1.··· .xl for l = k does not reduce at all. There is only head reduction. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
  • 13. Definition Definitions There is an infinite set of names, indicated by a capital. A term is either a name, or two terms combined by a dot. We write a.b.c as shorthand for (a.b).c. A program P consists of a set of rules, of the form Name.variable.··· .variable def −→ term over those variables That rule defines that name. Each rule defines a different name. If “N.x1 .··· .xk def −→ r” ∈ P, then we reduce N.t → r[t/x]. Term N.x1.··· .xl for l = k does not reduce at all. There is only head reduction. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 5 / 22
  • 14. Long-term goal Long-term goal Formally modeling programming languages Hopefully as a base for better languages Operational semantics Running time: #steps ∼ seconds CPU time Warning: some unsubstantiated claims Compositional Facilitates proving properties Deterministic by nature Works with continuations Explained later Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
  • 15. Long-term goal Long-term goal Formally modeling programming languages Hopefully as a base for better languages Operational semantics Running time: #steps ∼ seconds CPU time Warning: some unsubstantiated claims Compositional Facilitates proving properties Deterministic by nature Works with continuations Explained later Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 6 / 22
  • 16. Interfaces, not pattern matching Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 7 / 22
  • 17. Interfaces, not pattern matching Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 8 / 22
  • 18. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero)) → Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
  • 19. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Add.r.Zero.(S.Zero) → S.Zero.(r.Zero).(Add.r.(S.Zero)) → Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 9 / 22
  • 20. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y What can we feed to Add? Zero S.(··· .(S.Zero)···) Something else? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
  • 21. Interfaces, not pattern matching Natural numbers Slightly similar to lambda calculus Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y What can we feed to Add? Zero S.(··· .(S.Zero)···) Something else? Yes! Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 10 / 22
  • 22. Interfaces, not pattern matching Natural numbers Compatible naturals Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y We define when a term t represents natural number n. 1 t represents 0 if ∀z,s : t.z.s z Informally: t “behaves the same as” Zero 2 t represents n +1 if ∀z,s : t.z.s s.q, and q represents n Informally: t “behaves the same as” S.q With this, we can define LazyFact such that LazyFact.x represents (x!). (Omitted.) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
  • 23. Interfaces, not pattern matching Natural numbers Compatible naturals Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y With this, we can define LazyFact such that LazyFact.x represents (x!). (Omitted.) Add.r.Zero.(LazyFact.(S.Zero)) → LazyFact.(S.Zero).(r.Zero).(Add.r.(S.Zero)) Add.r.(S.Zero).Zero → Zero.(r.(S.Zero)).(Add.r.(S.(S.Zero))) → r.(S.Zero) Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
  • 24. Interfaces, not pattern matching Natural numbers Compatible naturals Zero.z.s def −→ z S.x.z.s def −→ s.x Add.r.x.y def −→ y.(r.x).(Add.r.(S.x)) Algorithm: x +0 = x x +S(y) = S(x)+y With this, we can define LazyFact such that LazyFact.x represents (x!). (Omitted.) Add.r.Zero.(LazyFact.(S.Zero)) r.(S.Zero) Two types of function names Call-by-value / eager: calculate result, fill in in continuation Call-by-name / lazy: compatible with Sn.Zero but delayed computation Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 11 / 22
  • 25. The importance of head reduction Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 12 / 22
  • 26. The importance of head reduction Outline 1 First look 2 Definition 3 Long-term goal 4 Interfaces, not pattern matching 5 The importance of head reduction 6 Relation to lambda calculus 7 Conclusion Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 13 / 22
  • 27. The importance of head reduction Operational semantics Lambda calculus (normal order) Reduction using two instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] as presented in [Levy(2001)] Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 14 / 22
  • 28. The importance of head reduction Back to modeling programs Lambda calculus λx.+ (f x) (g x) M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] Programming language fun x → (f x) + (g x) M N Apply function object to argument fun x → M Make function object In “real languages”, functions throw exceptions and have other side effects. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
  • 29. The importance of head reduction Back to modeling programs Lambda calculus λx.+ (f x) (g x) M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] Programming language fun x → (f x) + (g x) throws exception now what? M N Apply function object to argument fun x → M Make function object In “real languages”, functions throw exceptions and have other side effects. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 15 / 22
  • 30. The importance of head reduction Operational semantics Computational models with control Lambda calculus + continuations (λC) Reduction using four instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] A M Empty the stack, continue in M C M Empty the stack, continue in M (λx.S x) where function S ‘restores’ the previous stack (details omitted) Can model exception-like facilities CPS transformation to transform λC terms to λ terms Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 16 / 22
  • 31. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 32. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler What is this subset, really? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 33. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler What is this subset, really? Can we describe it? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 34. The importance of head reduction CPS transformation λC CPS transformation −−−−−−−−−−−→ subset of λ, makes minimal use of stack Two calculi in action: λC calculus: M N, λx.M, A M, C M Expressive Subset of λ calculus: M N, λx.M Simpler What is this subset, really? Can we describe it? An elegant model of computation, perhaps? Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 17 / 22
  • 35. The importance of head reduction Lambda calculus vs. continuation calculus λC Four instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] A M Empty the stack, continue in M C M Empty the stack, continue in M (λx.S x) where function S ‘restores’ the stack Continuation calculus One instruction on the top level, using program P n.t1.··· .tk Empty the stack, continue in r[t/x] if n.x1 .··· .xk def −→ r ∈ P Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
  • 36. The importance of head reduction Lambda calculus vs. continuation calculus λC Four instructions on the top level M N Push N on stack, continue in M λx.M Pop N off stack, continue in M[N/x] A M Empty the stack, continue in M C M Empty the stack, continue in M (λx.S x) where function S ‘restores’ the stack Continuation calculus One instruction on the top level, using program P n.t1.··· .tk Empty the stack, continue in r[t/x] if n.x1 .··· .xk def −→ r ∈ P Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 18 / 22
  • 37. The importance of head reduction Continuation calculus Continuation calculus One instruction on the top level, using program P n.t1.··· .tk Continue in r[t/x] if n.x1 .··· .xk def −→ r ∈ P No stack needed, because n.t1.··· .tl does not reduce for l = k. Subterms are not reduced Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 19 / 22
  • 38. Relation to lambda calculus Relation to lambda calculus λ,λC CPS transformation −−−−−−−−−−−→ subset of λ subset of λ λx to rules∗ −−−−−−−−−−−−−−−−−−−−−− unfold† rules to λx CC ∗ λx to rules: involves a supercombinator transformation † Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references Catchphrase CC is more limited than λ, thus more suitable to model continuations Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
  • 39. Relation to lambda calculus Relation to lambda calculus λ,λC CPS transformation −−−−−−−−−−−→ subset of λ subset of λ λx to rules∗ −−−−−−−−−−−−−−−−−−−−−− unfold† rules to λx CC ∗ λx to rules: involves a supercombinator transformation † Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic references Catchphrase CC is more limited than λ, thus more suitable to model continuations Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 20 / 22
  • 40. Conclusion Conclusion CC is a constrained term rewriting system CC is deterministic Only head reduction As a consequence, Suitable for control with continuations (exceptions) CC is similar to a subset of lambda calculus Allows both eager and lazy function terms call-by-value vs. call-by-name Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 21 / 22
  • 41. Appendix Bibliography P.B. Levy. Call-by-push-value. PhD thesis, Queen Mary, University of London, 2001. Geron, Geuvers (TU/e, RU) Continuation calculus TERESE May 2013 22 / 22