SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Discrete Mathematics - All chapters
Discrete Mathematics - All chapters Discrete Mathematics - All chapters
Discrete Mathematics - All chapters
Omnia A. Abdullah
 

Was ist angesagt? (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
 

Ähnlich wie Continuation calculus at Term Rewriting Seminar

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
irrrrr
 
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
Lukasz Obara
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

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