SlideShare una empresa de Scribd logo
1 de 58
Descargar para leer sin conexión
Continuation calculus
An alternative to lambda calculus
Midterm presentation
Bram Geron
(supervised by Herman Geuvers)
Eindhoven University of Technology
FSA colloquium, June 2013
Bram Geron (TU/e) Continuation calculus FSA colloquium 1 / 31
Modeling programming languages
Goals:
Assign exact meaning to programs
Assign exact meaning to functions
Reason on functions
Approaches:
Big-step semantics
Small-step semantics
Reduction to simpler calculus
Bram Geron (TU/e) Continuation calculus FSA colloquium 2 / 31
Modeling programming languages
Goals:
Assign exact meaning to programs
Assign exact meaning to functions
Reason on functions
Approaches:
Big-step semantics: lambda calculus
Small-step semantics: lambda calculus, continuation calculus
Reduction to simpler calculus: programming languages to λ or CC
Bram Geron (TU/e) Continuation calculus FSA colloquium 2 / 31
Modeling programming languages
Simple calculi
Lambda calculus
Tree of expressions
(fact 4)+1
β 25
Continuation calculus
Tree of “continuation terms”
Fact.(AddOne.Return).4
Return.25
Bram Geron (TU/e) Continuation calculus FSA colloquium 3 / 31
First look
Outline
1 First look
2 Definition
3 Long-term goal
4 The importance of head reduction
5 Case study: list multiplication
6 Conclusion
Bram Geron (TU/e) Continuation calculus FSA colloquium 4 / 31
First look Rules, names, variables, terms
CC is a term rewriting system in a constrained shape
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
First look Rules, names, variables, terms
CC is a term rewriting system in a constrained shape
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
First look Rules, names, variables, terms
CC is a term rewriting system in a constrained shape
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
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
−→ CPS transformation
Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
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
−→ CPS transformation
Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
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
−→ CPS transformation
Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
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
−→ CPS transformation
Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
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
−→ CPS transformation
Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
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
−→ CPS transformation
Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
First look Another example
Natural numbers
Representation and AddOne
We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by
S.(··· .(S.Zero)···). These terms are denoted n .
We implement the function AddOne, such that AddOne.r. n r. n +1 .
AddOne.r.m
def
−→ r.(S.m)
Bram Geron (TU/e) Continuation calculus FSA colloquium 7 / 31
First look Another example
Natural numbers
Behavior and Double
We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by
S.(··· .(S.Zero)···). These terms are denoted n .
There are rules for Zero and S:
Zero.z.s
def
−→ z s.t. 0 .z.s z
S.m.z.s
def
−→ s.m s.t. m +1 .z.s s. m
We can now make a function Double such that Double.r. n r. 2n .
Double.r.m
def
−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))
Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
First look Another example
Natural numbers
Behavior and Double
We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by
S.(··· .(S.Zero)···). These terms are denoted n .
We can now make a function Double such that Double.r. n r. 2n .
Double.r.m
def
−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))
Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
First look Another example
Natural numbers
Behavior and Double
We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by
S.(··· .(S.Zero)···). These terms are denoted n .
We can now make a function Double such that Double.r. n r. 2n .
Double.r.m
def
−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))
Double.r. 0 → Zero.(r. 0 ).(Double.(AddOne.(AddOne.r)))
→ r. 0
Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
First look Another example
Natural numbers
Behavior and Double
We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by
S.(··· .(S.Zero)···). These terms are denoted n .
We can now make a function Double such that Double.r. n r. 2n .
Double.r.m
def
−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))
Double.r. 2 → S. 1 .(r. 0 ).(Double.(AddOne.(AddOne.r)))
→ Double.(AddOne.(AddOne.r)). 1
→ S. 0 .(AddOne.(AddOne.r). 0 ).(Double.(AddOne.(AddOne.(AddOne.(Add
→ Double.(AddOne.(AddOne.(AddOne.(AddOne.r)))). 0
→ Zero.(AddOne.(AddOne.(AddOne.(AddOne.r))). 0 ).(Double.(AddOne.(Ad
→ AddOne.(AddOne.(AddOne.(AddOne.r))). 0
r. 4 in 4 steps
Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
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.
Bram Geron (TU/e) Continuation calculus FSA colloquium 9 / 31
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.
Bram Geron (TU/e) Continuation calculus FSA colloquium 9 / 31
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.
Bram Geron (TU/e) Continuation calculus FSA colloquium 9 / 31
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 10 / 31
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 10 / 31
The importance of head reduction
Outline
1 First look
2 Definition
3 Long-term goal
4 The importance of head reduction
5 Case study: list multiplication
6 Conclusion
Bram Geron (TU/e) Continuation calculus FSA colloquium 11 / 31
The importance of head reduction
Outline
1 First look
2 Definition
3 Long-term goal
4 The importance of head reduction
5 Case study: list multiplication
6 Conclusion
Bram Geron (TU/e) Continuation calculus FSA colloquium 12 / 31
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.
Bram Geron (TU/e) Continuation calculus FSA colloquium 13 / 31
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.
Bram Geron (TU/e) Continuation calculus FSA colloquium 13 / 31
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 14 / 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
Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 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
What is this subset, really?
Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 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
What is this subset, really?
Can we describe it?
Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 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
What is this subset, really?
Can we describe it?
An elegant model of computation, perhaps?
Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 16 / 31
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 16 / 31
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
Bram Geron (TU/e) Continuation calculus FSA colloquium 17 / 31
Case study: list multiplication
Outline
1 First look
2 Definition
3 Long-term goal
4 The importance of head reduction
5 Case study: list multiplication
6 Conclusion
Bram Geron (TU/e) Continuation calculus FSA colloquium 18 / 31
Case study: list multiplication
List multiplication
An algorithm
product [4,2,6] = 4∗2∗6 = 48
product l = case l of
| [] → 1
| [x]++xs → x ∗product xs
product [4,2,6] = 4∗(2∗(6∗1)) = 48
Bram Geron (TU/e) Continuation calculus FSA colloquium 19 / 31
Case study: list multiplication
List multiplication
An algorithm
product [4,2,6] = 4∗2∗6 = 48
product l = case l of
| [] → 1
| [x]++xs → x ∗product xs
product [4,2,6] = 4∗(2∗(6∗1)) = 48
Bram Geron (TU/e) Continuation calculus FSA colloquium 19 / 31
Case study: list multiplication
List multiplication
A better algorithm
product [4,0,6] = 4∗0∗6 = 0
product l = case l of
| [] → 1
| [x]++xs → x ∗product xs
product [4,0,6] = 4∗(0∗(6∗1)) = 0
Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
Case study: list multiplication
List multiplication
A better algorithm
product [4,0,6] = 4∗0∗6 = 0
product l =
try:
let subproduct l = case l of
| [] → 1
| [0]++xs → abort
| [x]++xs → x ∗subproduct xs
in subproduct l
catch abort :
0
Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
Case study: list multiplication
List multiplication
A better algorithm
product l =
try:
let subproduct l = case l of
| [] → 1
| [0]++xs → abort
| [x]++xs → x ∗subproduct xs
in subproduct l
catch abort :
0
product [4,0,6] = try: {4∗abort} catch abort : 0
= 0
Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
Case study: list multiplication
List multiplication
Implementation
Implemented ListMult with this behavior in continuation calculus
includes modeling of naturals and lists with CC rules
Proved correct
ListMult. l .r r. product l for all l ∈ ListN
Empirical evidence of efficiency
ListMult. [4,0,6] .r r. 0 in 10 steps
ListMult. [4,2,6] .r r. 48 in 339 steps
Bram Geron (TU/e) Continuation calculus FSA colloquium 21 / 31
Conclusion
Conclusion
CC is a term rewriting system in a constrained shape
CC is deterministic
Only head reduction
As a consequence,
Suitable for control with continuations (exceptions)
CC is similar to a subset of lambda calculus
Mimics running times of real programs to some degree
Bram Geron (TU/e) Continuation calculus FSA colloquium 22 / 31
Conclusion
Current state and future work
Joint paper with Herman Geuvers
Accepted in proceedings of COS 2013, 24–25 June
Future work:
Systematic translation of functional programming language to CC
Prove that this translation preserves semantics
Type system
Model hierarchical side-effects using an extension
Bram Geron (TU/e) Continuation calculus FSA colloquium 23 / 31
Conclusion
The End
Questions?
Bram Geron (TU/e) Continuation calculus FSA colloquium 24 / 31
Bibliography
Bibliography
Bram Geron (TU/e) Continuation calculus FSA colloquium 25 / 31
Extra slides
Extra slides
Extra slides
Bram Geron (TU/e) Continuation calculus FSA colloquium 26 / 31
Extra slides 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
Bram Geron (TU/e) Continuation calculus FSA colloquium 27 / 31
Extra slides 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
Bram Geron (TU/e) Continuation calculus FSA colloquium 27 / 31
Extra slides 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)
Bram Geron (TU/e) Continuation calculus FSA colloquium 28 / 31
Extra slides 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)
Bram Geron (TU/e) Continuation calculus FSA colloquium 28 / 31
Extra slides 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?
Bram Geron (TU/e) Continuation calculus FSA colloquium 29 / 31
Extra slides 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!
Bram Geron (TU/e) Continuation calculus FSA colloquium 29 / 31
Extra slides 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.)
Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
Extra slides 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)
Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
Extra slides 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
Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
Appendix
Ideas
Efficient te compileren?
OUTLOOK
Bram Geron (TU/e) Continuation calculus FSA colloquium 31 / 31

Más contenido relacionado

La actualidad más candente

RuleML 2015 Constraint Handling Rules - What Else?
RuleML 2015 Constraint Handling Rules - What Else?RuleML 2015 Constraint Handling Rules - What Else?
RuleML 2015 Constraint Handling Rules - What Else?RuleML
 
Characterizing the Distortion of Some Simple Euclidean Embeddings
Characterizing the Distortion of Some Simple Euclidean EmbeddingsCharacterizing the Distortion of Some Simple Euclidean Embeddings
Characterizing the Distortion of Some Simple Euclidean EmbeddingsDon Sheehy
 
Program Derivation of Operations in Finite Fields of Prime Order
Program Derivation of Operations in Finite Fields of Prime OrderProgram Derivation of Operations in Finite Fields of Prime Order
Program Derivation of Operations in Finite Fields of Prime OrderCharles Southerland
 
Semi-automatic ABC: a discussion
Semi-automatic ABC: a discussionSemi-automatic ABC: a discussion
Semi-automatic ABC: a discussionChristian Robert
 
Quasi newton
Quasi newtonQuasi newton
Quasi newtontokumoto
 
2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...
2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...
2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...kaliaragorn
 
Fundamental Theorem of Calculus
Fundamental Theorem of CalculusFundamental Theorem of Calculus
Fundamental Theorem of Calculusgizemk
 
A2 Computing Reverse Polish Notation Part 2
A2 Computing   Reverse Polish Notation Part 2A2 Computing   Reverse Polish Notation Part 2
A2 Computing Reverse Polish Notation Part 2pstevens1963
 
A note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integersA note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integersLukas Nabergall
 
Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...
Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...
Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...Tomonari Masada
 
20110319 parameterized algorithms_fomin_lecture03-04
20110319 parameterized algorithms_fomin_lecture03-0420110319 parameterized algorithms_fomin_lecture03-04
20110319 parameterized algorithms_fomin_lecture03-04Computer Science Club
 
Functions
FunctionsFunctions
FunctionsGaditek
 

La actualidad más candente (18)

RuleML 2015 Constraint Handling Rules - What Else?
RuleML 2015 Constraint Handling Rules - What Else?RuleML 2015 Constraint Handling Rules - What Else?
RuleML 2015 Constraint Handling Rules - What Else?
 
Characterizing the Distortion of Some Simple Euclidean Embeddings
Characterizing the Distortion of Some Simple Euclidean EmbeddingsCharacterizing the Distortion of Some Simple Euclidean Embeddings
Characterizing the Distortion of Some Simple Euclidean Embeddings
 
Program Derivation of Operations in Finite Fields of Prime Order
Program Derivation of Operations in Finite Fields of Prime OrderProgram Derivation of Operations in Finite Fields of Prime Order
Program Derivation of Operations in Finite Fields of Prime Order
 
Semi-automatic ABC: a discussion
Semi-automatic ABC: a discussionSemi-automatic ABC: a discussion
Semi-automatic ABC: a discussion
 
Unit iii
Unit iiiUnit iii
Unit iii
 
10.1.1.226.4381
10.1.1.226.438110.1.1.226.4381
10.1.1.226.4381
 
Quasi newton
Quasi newtonQuasi newton
Quasi newton
 
2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...
2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...
2015 01 09 - Rende - Unical - Martin Gebser: Clingo = Answer Set Programming ...
 
Fundamental Theorem of Calculus
Fundamental Theorem of CalculusFundamental Theorem of Calculus
Fundamental Theorem of Calculus
 
A2 Computing Reverse Polish Notation Part 2
A2 Computing   Reverse Polish Notation Part 2A2 Computing   Reverse Polish Notation Part 2
A2 Computing Reverse Polish Notation Part 2
 
A note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integersA note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integers
 
Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...
Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...
Steering Time-Dependent Estimation of Posteriors with Hyperparameter Indexing...
 
20110319 parameterized algorithms_fomin_lecture03-04
20110319 parameterized algorithms_fomin_lecture03-0420110319 parameterized algorithms_fomin_lecture03-04
20110319 parameterized algorithms_fomin_lecture03-04
 
Lar calc10 ch01_sec4
Lar calc10 ch01_sec4Lar calc10 ch01_sec4
Lar calc10 ch01_sec4
 
Functions
FunctionsFunctions
Functions
 
slides_v1
slides_v1slides_v1
slides_v1
 
Operation on signals - Independent variables
Operation on signals - Independent variablesOperation on signals - Independent variables
Operation on signals - Independent variables
 
3.4 deterministic pda
3.4 deterministic pda3.4 deterministic pda
3.4 deterministic pda
 

Similar a Colloquium presentation

Continuation calculus at Term Rewriting Seminar
Continuation calculus at Term Rewriting SeminarContinuation calculus at Term Rewriting Seminar
Continuation calculus at Term Rewriting Seminarbgeron
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting PosterChelsea Battell
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus AhsanIrshad8
 
Applications of partial differentiation
Applications of partial differentiationApplications of partial differentiation
Applications of partial differentiationVaibhav Tandel
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
Weekends with Competitive Programming
Weekends with Competitive ProgrammingWeekends with Competitive Programming
Weekends with Competitive ProgrammingNiharikaSingh839269
 
Introduction to TreeNet (2004)
Introduction to TreeNet (2004)Introduction to TreeNet (2004)
Introduction to TreeNet (2004)Salford Systems
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptxAIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptxZawarali786
 
Poggi analytics - star - 1a
Poggi   analytics - star - 1aPoggi   analytics - star - 1a
Poggi analytics - star - 1aGaston Liberman
 
Selected topics in Bayesian Optimization
Selected topics in Bayesian OptimizationSelected topics in Bayesian Optimization
Selected topics in Bayesian Optimizationginsby
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in rmanikanta361
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 

Similar a Colloquium presentation (20)

Continuation calculus at Term Rewriting Seminar
Continuation calculus at Term Rewriting SeminarContinuation calculus at Term Rewriting Seminar
Continuation calculus at Term Rewriting Seminar
 
2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
 
BP106RMT.pdf
BP106RMT.pdfBP106RMT.pdf
BP106RMT.pdf
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Applications of partial differentiation
Applications of partial differentiationApplications of partial differentiation
Applications of partial differentiation
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Weekends with Competitive Programming
Weekends with Competitive ProgrammingWeekends with Competitive Programming
Weekends with Competitive Programming
 
Introduction to TreeNet (2004)
Introduction to TreeNet (2004)Introduction to TreeNet (2004)
Introduction to TreeNet (2004)
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Big o
Big oBig o
Big o
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
HIGHER MATHEMATICS
HIGHER MATHEMATICSHIGHER MATHEMATICS
HIGHER MATHEMATICS
 
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptxAIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
AIOU Code 803 Mathematics for Economists Semester Spring 2022 Assignment 2.pptx
 
Unit 3.4
Unit 3.4Unit 3.4
Unit 3.4
 
Poggi analytics - star - 1a
Poggi   analytics - star - 1aPoggi   analytics - star - 1a
Poggi analytics - star - 1a
 
Selected topics in Bayesian Optimization
Selected topics in Bayesian OptimizationSelected topics in Bayesian Optimization
Selected topics in Bayesian Optimization
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Cs501 fd nf
Cs501 fd nfCs501 fd nf
Cs501 fd nf
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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 MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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 DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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 WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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.pptxEarley Information Science
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Colloquium presentation

  • 1. Continuation calculus An alternative to lambda calculus Midterm presentation Bram Geron (supervised by Herman Geuvers) Eindhoven University of Technology FSA colloquium, June 2013 Bram Geron (TU/e) Continuation calculus FSA colloquium 1 / 31
  • 2. Modeling programming languages Goals: Assign exact meaning to programs Assign exact meaning to functions Reason on functions Approaches: Big-step semantics Small-step semantics Reduction to simpler calculus Bram Geron (TU/e) Continuation calculus FSA colloquium 2 / 31
  • 3. Modeling programming languages Goals: Assign exact meaning to programs Assign exact meaning to functions Reason on functions Approaches: Big-step semantics: lambda calculus Small-step semantics: lambda calculus, continuation calculus Reduction to simpler calculus: programming languages to λ or CC Bram Geron (TU/e) Continuation calculus FSA colloquium 2 / 31
  • 4. Modeling programming languages Simple calculi Lambda calculus Tree of expressions (fact 4)+1 β 25 Continuation calculus Tree of “continuation terms” Fact.(AddOne.Return).4 Return.25 Bram Geron (TU/e) Continuation calculus FSA colloquium 3 / 31
  • 5. First look Outline 1 First look 2 Definition 3 Long-term goal 4 The importance of head reduction 5 Case study: list multiplication 6 Conclusion Bram Geron (TU/e) Continuation calculus FSA colloquium 4 / 31
  • 6. First look Rules, names, variables, terms CC is a term rewriting system in a constrained shape 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
  • 7. First look Rules, names, variables, terms CC is a term rewriting system in a constrained shape 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
  • 8. First look Rules, names, variables, terms CC is a term rewriting system in a constrained shape 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
  • 9. 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 −→ CPS transformation Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  • 10. 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 −→ CPS transformation Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  • 11. 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 −→ CPS transformation Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  • 12. 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 −→ CPS transformation Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  • 13. 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 −→ CPS transformation Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  • 14. 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 −→ CPS transformation Bram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  • 15. First look Another example Natural numbers Representation and AddOne We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by S.(··· .(S.Zero)···). These terms are denoted n . We implement the function AddOne, such that AddOne.r. n r. n +1 . AddOne.r.m def −→ r.(S.m) Bram Geron (TU/e) Continuation calculus FSA colloquium 7 / 31
  • 16. First look Another example Natural numbers Behavior and Double We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by S.(··· .(S.Zero)···). These terms are denoted n . There are rules for Zero and S: Zero.z.s def −→ z s.t. 0 .z.s z S.m.z.s def −→ s.m s.t. m +1 .z.s s. m We can now make a function Double such that Double.r. n r. 2n . Double.r.m def −→ m.(r.Zero).(Double.(AddOne.(AddOne.r))) Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  • 17. First look Another example Natural numbers Behavior and Double We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by S.(··· .(S.Zero)···). These terms are denoted n . We can now make a function Double such that Double.r. n r. 2n . Double.r.m def −→ m.(r.Zero).(Double.(AddOne.(AddOne.r))) Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  • 18. First look Another example Natural numbers Behavior and Double We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by S.(··· .(S.Zero)···). These terms are denoted n . We can now make a function Double such that Double.r. n r. 2n . Double.r.m def −→ m.(r.Zero).(Double.(AddOne.(AddOne.r))) Double.r. 0 → Zero.(r. 0 ).(Double.(AddOne.(AddOne.r))) → r. 0 Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  • 19. First look Another example Natural numbers Behavior and Double We represent 0 by Zero, 3 by S.(S.(S.Zero)), and n by S.(··· .(S.Zero)···). These terms are denoted n . We can now make a function Double such that Double.r. n r. 2n . Double.r.m def −→ m.(r.Zero).(Double.(AddOne.(AddOne.r))) Double.r. 2 → S. 1 .(r. 0 ).(Double.(AddOne.(AddOne.r))) → Double.(AddOne.(AddOne.r)). 1 → S. 0 .(AddOne.(AddOne.r). 0 ).(Double.(AddOne.(AddOne.(AddOne.(Add → Double.(AddOne.(AddOne.(AddOne.(AddOne.r)))). 0 → Zero.(AddOne.(AddOne.(AddOne.(AddOne.r))). 0 ).(Double.(AddOne.(Ad → AddOne.(AddOne.(AddOne.(AddOne.r))). 0 r. 4 in 4 steps Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  • 20. 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. Bram Geron (TU/e) Continuation calculus FSA colloquium 9 / 31
  • 21. 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. Bram Geron (TU/e) Continuation calculus FSA colloquium 9 / 31
  • 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. Bram Geron (TU/e) Continuation calculus FSA colloquium 9 / 31
  • 23. 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 10 / 31
  • 24. 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 10 / 31
  • 25. The importance of head reduction Outline 1 First look 2 Definition 3 Long-term goal 4 The importance of head reduction 5 Case study: list multiplication 6 Conclusion Bram Geron (TU/e) Continuation calculus FSA colloquium 11 / 31
  • 26. The importance of head reduction Outline 1 First look 2 Definition 3 Long-term goal 4 The importance of head reduction 5 Case study: list multiplication 6 Conclusion Bram Geron (TU/e) Continuation calculus FSA colloquium 12 / 31
  • 27. 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. Bram Geron (TU/e) Continuation calculus FSA colloquium 13 / 31
  • 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) 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. Bram Geron (TU/e) Continuation calculus FSA colloquium 13 / 31
  • 29. 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 14 / 31
  • 30. 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  • 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 What is this subset, really? Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  • 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? Can we describe it? Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  • 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? An elegant model of computation, perhaps? Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  • 34. 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 16 / 31
  • 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 16 / 31
  • 36. 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 17 / 31
  • 37. Case study: list multiplication Outline 1 First look 2 Definition 3 Long-term goal 4 The importance of head reduction 5 Case study: list multiplication 6 Conclusion Bram Geron (TU/e) Continuation calculus FSA colloquium 18 / 31
  • 38. Case study: list multiplication List multiplication An algorithm product [4,2,6] = 4∗2∗6 = 48 product l = case l of | [] → 1 | [x]++xs → x ∗product xs product [4,2,6] = 4∗(2∗(6∗1)) = 48 Bram Geron (TU/e) Continuation calculus FSA colloquium 19 / 31
  • 39. Case study: list multiplication List multiplication An algorithm product [4,2,6] = 4∗2∗6 = 48 product l = case l of | [] → 1 | [x]++xs → x ∗product xs product [4,2,6] = 4∗(2∗(6∗1)) = 48 Bram Geron (TU/e) Continuation calculus FSA colloquium 19 / 31
  • 40. Case study: list multiplication List multiplication A better algorithm product [4,0,6] = 4∗0∗6 = 0 product l = case l of | [] → 1 | [x]++xs → x ∗product xs product [4,0,6] = 4∗(0∗(6∗1)) = 0 Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
  • 41. Case study: list multiplication List multiplication A better algorithm product [4,0,6] = 4∗0∗6 = 0 product l = try: let subproduct l = case l of | [] → 1 | [0]++xs → abort | [x]++xs → x ∗subproduct xs in subproduct l catch abort : 0 Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
  • 42. Case study: list multiplication List multiplication A better algorithm product l = try: let subproduct l = case l of | [] → 1 | [0]++xs → abort | [x]++xs → x ∗subproduct xs in subproduct l catch abort : 0 product [4,0,6] = try: {4∗abort} catch abort : 0 = 0 Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
  • 43. Case study: list multiplication List multiplication Implementation Implemented ListMult with this behavior in continuation calculus includes modeling of naturals and lists with CC rules Proved correct ListMult. l .r r. product l for all l ∈ ListN Empirical evidence of efficiency ListMult. [4,0,6] .r r. 0 in 10 steps ListMult. [4,2,6] .r r. 48 in 339 steps Bram Geron (TU/e) Continuation calculus FSA colloquium 21 / 31
  • 44. Conclusion Conclusion CC is a term rewriting system in a constrained shape CC is deterministic Only head reduction As a consequence, Suitable for control with continuations (exceptions) CC is similar to a subset of lambda calculus Mimics running times of real programs to some degree Bram Geron (TU/e) Continuation calculus FSA colloquium 22 / 31
  • 45. Conclusion Current state and future work Joint paper with Herman Geuvers Accepted in proceedings of COS 2013, 24–25 June Future work: Systematic translation of functional programming language to CC Prove that this translation preserves semantics Type system Model hierarchical side-effects using an extension Bram Geron (TU/e) Continuation calculus FSA colloquium 23 / 31
  • 46. Conclusion The End Questions? Bram Geron (TU/e) Continuation calculus FSA colloquium 24 / 31
  • 47. Bibliography Bibliography Bram Geron (TU/e) Continuation calculus FSA colloquium 25 / 31
  • 48. Extra slides Extra slides Extra slides Bram Geron (TU/e) Continuation calculus FSA colloquium 26 / 31
  • 49. Extra slides 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 27 / 31
  • 50. Extra slides 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 27 / 31
  • 51. Extra slides 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) Bram Geron (TU/e) Continuation calculus FSA colloquium 28 / 31
  • 52. Extra slides 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) Bram Geron (TU/e) Continuation calculus FSA colloquium 28 / 31
  • 53. Extra slides 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? Bram Geron (TU/e) Continuation calculus FSA colloquium 29 / 31
  • 54. Extra slides 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! Bram Geron (TU/e) Continuation calculus FSA colloquium 29 / 31
  • 55. Extra slides 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.) Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
  • 56. Extra slides 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) Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
  • 57. Extra slides 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 Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
  • 58. Appendix Ideas Efficient te compileren? OUTLOOK Bram Geron (TU/e) Continuation calculus FSA colloquium 31 / 31