Continuation calculus (CC) is an alternative to lambda calculus, where the order of evaluation is determined by programs themselves. Owing to its simplicity, continuations are no unusual terms. This makes it natural to model programs with nonlocal control flow, as with exceptions and call-by-name functions.
This presentation includes the list multiplication example.
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
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