Continuation calculusAn alternative to lambda calculusMidterm presentationBram Geron(supervised by Herman Geuvers)Eindhove...
Modeling programming languagesGoals:Assign exact meaning to programsAssign exact meaning to functionsReason on functionsAp...
Modeling programming languagesGoals:Assign exact meaning to programsAssign exact meaning to functionsReason on functionsAp...
Modeling programming languagesSimple calculiLambda calculusTree of expressions(fact 4)+1β 25Continuation calculusTree of “...
First lookOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case study: list multiplicatio...
First look Rules, names, variables, termsCC is a term rewriting system in a constrained shapeComp.f .g.xdef−→ f .(g.x)Comp...
First look Rules, names, variables, termsCC is a term rewriting system in a constrained shaperuleCompname(constant).f .g.x...
First look Rules, names, variables, termsCC is a term rewriting system in a constrained shaperuleCompname(constant).f .g.x...
First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.f .g....
First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.f .g....
First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.f .g....
First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.r.f ....
First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.r.f ....
First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.r.f ....
First look Another exampleNatural numbersRepresentation and AddOneWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(...
First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(...
First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(...
First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(...
First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(...
DefinitionDefinitionsThere is an infinite set of names, indicated by a capital.A term is either a name, or two terms combined...
DefinitionDefinitionsThere is an infinite set of names, indicated by a capital.A term is either a name, or two terms combined...
DefinitionDefinitionsThere is an infinite set of names, indicated by a capital.A term is either a name, or two terms combined...
Long-term goalLong-term goalFormally modeling programming languagesHopefully as a base for better languagesOperational sem...
Long-term goalLong-term goalFormally modeling programming languagesHopefully as a base for better languagesOperational sem...
The importance of head reductionOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case stu...
The importance of head reductionOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case stu...
The importance of head reductionBack to modeling programsLambda calculusλx.+ (f x) (g x)M N Push N on stack,continue in Mλ...
The importance of head reductionBack to modeling programsLambda calculusλx.+ (f x) (g x)M N Push N on stack,continue in Mλ...
The importance of head reductionOperational semanticsComputational models with controlLambda calculus + continuations (λC)...
The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stack...
The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stack...
The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stack...
The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stack...
The importance of head reductionLambda calculus vs. continuation calculusλCFour instructions on the top levelM N Push N on...
The importance of head reductionLambda calculus vs. continuation calculusλCFour instructions on the top levelM N Push N on...
The importance of head reductionContinuation calculusContinuation calculusOne instruction on the top level, using program ...
Case study: list multiplicationOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case stud...
Case study: list multiplicationList multiplicationAn algorithmproduct [4,2,6] = 4∗2∗6 = 48product l = case l of| [] → 1| [...
Case study: list multiplicationList multiplicationAn algorithmproduct [4,2,6] = 4∗2∗6 = 48product l = case l of| [] → 1| [...
Case study: list multiplicationList multiplicationA better algorithmproduct [4,0,6] = 4∗0∗6 = 0product l = case l of| [] →...
Case study: list multiplicationList multiplicationA better algorithmproduct [4,0,6] = 4∗0∗6 = 0product l =try:let subprodu...
Case study: list multiplicationList multiplicationA better algorithmproduct l =try:let subproduct l = case l of| [] → 1| [...
Case study: list multiplicationList multiplicationImplementationImplemented ListMult with this behavior in continuation ca...
ConclusionConclusionCC is a term rewriting system in a constrained shapeCC is deterministicOnly head reductionAs a consequ...
ConclusionCurrent state and future workJoint paper with Herman GeuversAccepted in proceedings of COS 2013, 24–25 JuneFutur...
ConclusionThe EndQuestions?Bram Geron (TU/e) Continuation calculus FSA colloquium 24 / 31
BibliographyBibliographyBram Geron (TU/e) Continuation calculus FSA colloquium 25 / 31
Extra slidesExtra slidesExtra slidesBram Geron (TU/e) Continuation calculus FSA colloquium 26 / 31
Extra slides Relation to lambda calculusRelation to lambda calculusλ,λCCPS transformation−−−−−−−−−−−→ subset of λsubset of...
Extra slides Relation to lambda calculusRelation to lambda calculusλ,λCCPS transformation−−−−−−−−−−−→ subset of λsubset of...
Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→...
Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→...
Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→...
Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→...
Extra slides Interfaces, not pattern matchingNatural numbersCompatible naturalsZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef...
Extra slides Interfaces, not pattern matchingNatural numbersCompatible naturalsZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef...
Extra slides Interfaces, not pattern matchingNatural numbersCompatible naturalsZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef...
AppendixIdeasEfficient te compileren?OUTLOOKBram Geron (TU/e) Continuation calculus FSA colloquium 31 / 31
Upcoming SlideShare
Loading in …5
×

Colloquium presentation

799 views

Published on

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.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
799
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Colloquium presentation

  1. 1. Continuation calculusAn alternative to lambda calculusMidterm presentationBram Geron(supervised by Herman Geuvers)Eindhoven University of TechnologyFSA colloquium, June 2013Bram Geron (TU/e) Continuation calculus FSA colloquium 1 / 31
  2. 2. Modeling programming languagesGoals:Assign exact meaning to programsAssign exact meaning to functionsReason on functionsApproaches:Big-step semanticsSmall-step semanticsReduction to simpler calculusBram Geron (TU/e) Continuation calculus FSA colloquium 2 / 31
  3. 3. Modeling programming languagesGoals:Assign exact meaning to programsAssign exact meaning to functionsReason on functionsApproaches:Big-step semantics: lambda calculusSmall-step semantics: lambda calculus, continuation calculusReduction to simpler calculus: programming languages to λ or CCBram Geron (TU/e) Continuation calculus FSA colloquium 2 / 31
  4. 4. Modeling programming languagesSimple calculiLambda calculusTree of expressions(fact 4)+1β 25Continuation calculusTree of “continuation terms”Fact.(AddOne.Return).4Return.25Bram Geron (TU/e) Continuation calculus FSA colloquium 3 / 31
  5. 5. First lookOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case study: list multiplication6 ConclusionBram Geron (TU/e) Continuation calculus FSA colloquium 4 / 31
  6. 6. First look Rules, names, variables, termsCC is a term rewriting system in a constrained shapeComp.f .g.xdef−→ f .(g.x)Comp.AddOne.Fact.4 → AddOne.(Fact.4)RulesOne definition per name(max)No pattern matchingOnly head reductionConsequencesDeterministicSimple operational semanticsSuitable for modelingcontinuations, hence exceptionsBram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
  7. 7. First look Rules, names, variables, termsCC is a term rewriting system in a constrained shaperuleCompname(constant).f .g.xvariablesdef−→ f .(g.x)Comp.AddOne.Fact.4term→ AddOne.(Fact.4)termRulesOne definition per name(max)No pattern matchingOnly head reductionConsequencesDeterministicSimple operational semanticsSuitable for modelingcontinuations, hence exceptionsBram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
  8. 8. First look Rules, names, variables, termsCC is a term rewriting system in a constrained shaperuleCompname(constant).f .g.xvariablesdef−→ f .(g.x)Comp.AddOne.Fact.4term→ AddOne.(Fact.4)termRulesOne definition per name(max)No pattern matchingOnly head reductionConsequencesDeterministicSimple operational semanticsSuitable for modelingcontinuations, hence exceptionsBram Geron (TU/e) Continuation calculus FSA colloquium 5 / 31
  9. 9. First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.f .g.xdef−→ f .(g.x)Comp.AddOne.Fact.4 → AddOne.(Fact).4Realistic names:Fact.r.x r.x!AddOne.r.x r.(x +1)Fact.(AddOne.r).4 AddOne.r.24r.25−→ CPS transformationBram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  10. 10. First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.f .g.xdef−→ f .(g.x)Comp.AddOne.Fact.4 → AddOne.(Fact).4Realistic names:Fact.r.x r.x!AddOne.r.x r.(x +1)Fact.(AddOne.r).4 AddOne.r.24r.25−→ CPS transformationBram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  11. 11. First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.f .g.xdef−→ f .(g.x)Comp.AddOne.Fact.4 → AddOne.(Fact).4Realistic names:Fact.r.x r.x!AddOne.r.x r.(x +1)Fact.(AddOne.r).4 AddOne.r.24r.25−→ CPS transformationBram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  12. 12. First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.r.f .g.xdef−→ g.(f .r).xComp.r.AddOne.Fact.4 → Fact.(AddOne.r).4Realistic names:Fact.r.x r.x!AddOne.r.x r.(x +1)Fact.(AddOne.r).4 AddOne.r.24r.25−→ CPS transformationBram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  13. 13. First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.r.f .g.xdef−→ g.(f .r).xComp.r.AddOne.Fact.4 → Fact.(AddOne.r).4Realistic names:Fact.r.x r.x!AddOne.r.x r.(x +1)Fact.(AddOne.r).4 AddOne.r.24r.25−→ CPS transformationBram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  14. 14. First look Head reduction: continuation passing styleFunctions fill in the result in their continuation parameterComp.r.f .g.xdef−→ g.(f .r).xComp.r.AddOne.Fact.4 → Fact.(AddOne.r).4Realistic names:Fact.r.x r.x!AddOne.r.x r.(x +1)Fact.(AddOne.r).4 AddOne.r.24r.25−→ CPS transformationBram Geron (TU/e) Continuation calculus FSA colloquium 6 / 31
  15. 15. First look Another exampleNatural numbersRepresentation and AddOneWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(S.Zero)···). These terms are denoted n .We implement the function AddOne, such that AddOne.r. n r. n +1 .AddOne.r.mdef−→ r.(S.m)Bram Geron (TU/e) Continuation calculus FSA colloquium 7 / 31
  16. 16. First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(S.Zero)···). These terms are denoted n .There are rules for Zero and S:Zero.z.sdef−→ z s.t. 0 .z.s zS.m.z.sdef−→ s.m s.t. m +1 .z.s s. mWe can now make a function Double such that Double.r. n r. 2n .Double.r.mdef−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  17. 17. First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(S.Zero)···). These terms are denoted n .We can now make a function Double such that Double.r. n r. 2n .Double.r.mdef−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  18. 18. First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(S.Zero)···). These terms are denoted n .We can now make a function Double such that Double.r. n r. 2n .Double.r.mdef−→ m.(r.Zero).(Double.(AddOne.(AddOne.r)))Double.r. 0 → Zero.(r. 0 ).(Double.(AddOne.(AddOne.r)))→ r. 0Bram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  19. 19. First look Another exampleNatural numbersBehavior and DoubleWe represent 0 by Zero, 3 by S.(S.(S.Zero)), and n byS.(··· .(S.Zero)···). These terms are denoted n .We can now make a function Double such that Double.r. n r. 2n .Double.r.mdef−→ 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))). 0r. 4 in 4 stepsBram Geron (TU/e) Continuation calculus FSA colloquium 8 / 31
  20. 20. DefinitionDefinitionsThere 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 formName.variable.··· .variabledef−→ term over those variablesThat rule defines that name.Each rule defines a different name.If “N.x1 .··· .xkdef−→ 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. 21. DefinitionDefinitionsThere 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 formName.variable.··· .variabledef−→ term over those variablesThat rule defines that name.Each rule defines a different name.If “N.x1 .··· .xkdef−→ 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. 22. DefinitionDefinitionsThere 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 formName.variable.··· .variabledef−→ term over those variablesThat rule defines that name.Each rule defines a different name.If “N.x1 .··· .xkdef−→ 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. 23. Long-term goalLong-term goalFormally modeling programming languagesHopefully as a base for better languagesOperational semanticsRunning time: #steps ∼ seconds CPU timeWarning: some unsubstantiated claimsCompositionalFacilitates proving propertiesDeterministic by natureWorks with continuationsExplained laterBram Geron (TU/e) Continuation calculus FSA colloquium 10 / 31
  24. 24. Long-term goalLong-term goalFormally modeling programming languagesHopefully as a base for better languagesOperational semanticsRunning time: #steps ∼ seconds CPU timeWarning: some unsubstantiated claimsCompositionalFacilitates proving propertiesDeterministic by natureWorks with continuationsExplained laterBram Geron (TU/e) Continuation calculus FSA colloquium 10 / 31
  25. 25. The importance of head reductionOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case study: list multiplication6 ConclusionBram Geron (TU/e) Continuation calculus FSA colloquium 11 / 31
  26. 26. The importance of head reductionOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case study: list multiplication6 ConclusionBram Geron (TU/e) Continuation calculus FSA colloquium 12 / 31
  27. 27. The importance of head reductionBack to modeling programsLambda 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 languagefun x → (f x) + (g x)M N Apply function objectto argumentfun x → M Make function objectIn “real languages”, functions throw exceptions and have other side effects.Bram Geron (TU/e) Continuation calculus FSA colloquium 13 / 31
  28. 28. The importance of head reductionBack to modeling programsLambda 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 languagefun x → (f x) + (g x)throws exceptionnow what?M N Apply function objectto argumentfun x → M Make function objectIn “real languages”, functions throw exceptions and have other side effects.Bram Geron (TU/e) Continuation calculus FSA colloquium 13 / 31
  29. 29. The importance of head reductionOperational semanticsComputational models with controlLambda calculus + continuations (λC)Reduction using four instructions on the top levelM 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 MC M Empty the stack, continue in M (λx.S x)where function S ‘restores’ the previous stack(details omitted)Can model exception-like facilitiesCPS transformation to transform λC terms to λ termsBram Geron (TU/e) Continuation calculus FSA colloquium 14 / 31
  30. 30. The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stackTwo calculi in action:λC calculus: M N, λx.M, A M, C MExpressiveSubset of λ calculus: M N, λx.MSimplerBram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  31. 31. The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stackTwo calculi in action:λC calculus: M N, λx.M, A M, C MExpressiveSubset of λ calculus: M N, λx.MSimplerWhat is this subset, really?Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  32. 32. The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stackTwo calculi in action:λC calculus: M N, λx.M, A M, C MExpressiveSubset of λ calculus: M N, λx.MSimplerWhat is this subset, really?Can we describe it?Bram Geron (TU/e) Continuation calculus FSA colloquium 15 / 31
  33. 33. The importance of head reductionCPS transformationλCCPS transformation−−−−−−−−−−−→ subset of λ, makes minimal use of stackTwo calculi in action:λC calculus: M N, λx.M, A M, C MExpressiveSubset of λ calculus: M N, λx.MSimplerWhat 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. 34. The importance of head reductionLambda calculus vs. continuation calculusλCFour instructions on the top levelM 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 MC M Empty the stack, continue in M (λx.S x)where function S ‘restores’ the stackContinuation calculusOne instruction on the top level, using program Pn.t1.··· .tk Empty the stack, continue in r[t/x]if n.x1 .··· .xkdef−→ r ∈ PBram Geron (TU/e) Continuation calculus FSA colloquium 16 / 31
  35. 35. The importance of head reductionLambda calculus vs. continuation calculusλCFour instructions on the top levelM 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 MC M Empty the stack, continue in M (λx.S x)where function S ‘restores’ the stackContinuation calculusOne instruction on the top level, using program Pn.t1.··· .tk Empty the stack, continue in r[t/x]if n.x1 .··· .xkdef−→ r ∈ PBram Geron (TU/e) Continuation calculus FSA colloquium 16 / 31
  36. 36. The importance of head reductionContinuation calculusContinuation calculusOne instruction on the top level, using program Pn.t1.··· .tk Continue in r[t/x]if n.x1 .··· .xkdef−→ r ∈ PNo stack needed, becausen.t1.··· .tl does not reduce for l = k.Subterms are not reducedBram Geron (TU/e) Continuation calculus FSA colloquium 17 / 31
  37. 37. Case study: list multiplicationOutline1 First look2 Definition3 Long-term goal4 The importance of head reduction5 Case study: list multiplication6 ConclusionBram Geron (TU/e) Continuation calculus FSA colloquium 18 / 31
  38. 38. Case study: list multiplicationList multiplicationAn algorithmproduct [4,2,6] = 4∗2∗6 = 48product l = case l of| [] → 1| [x]++xs → x ∗product xsproduct [4,2,6] = 4∗(2∗(6∗1)) = 48Bram Geron (TU/e) Continuation calculus FSA colloquium 19 / 31
  39. 39. Case study: list multiplicationList multiplicationAn algorithmproduct [4,2,6] = 4∗2∗6 = 48product l = case l of| [] → 1| [x]++xs → x ∗product xsproduct [4,2,6] = 4∗(2∗(6∗1)) = 48Bram Geron (TU/e) Continuation calculus FSA colloquium 19 / 31
  40. 40. Case study: list multiplicationList multiplicationA better algorithmproduct [4,0,6] = 4∗0∗6 = 0product l = case l of| [] → 1| [x]++xs → x ∗product xsproduct [4,0,6] = 4∗(0∗(6∗1)) = 0Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
  41. 41. Case study: list multiplicationList multiplicationA better algorithmproduct [4,0,6] = 4∗0∗6 = 0product l =try:let subproduct l = case l of| [] → 1| [0]++xs → abort| [x]++xs → x ∗subproduct xsin subproduct lcatch abort :0Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
  42. 42. Case study: list multiplicationList multiplicationA better algorithmproduct l =try:let subproduct l = case l of| [] → 1| [0]++xs → abort| [x]++xs → x ∗subproduct xsin subproduct lcatch abort :0product [4,0,6] = try: {4∗abort} catch abort : 0= 0Bram Geron (TU/e) Continuation calculus FSA colloquium 20 / 31
  43. 43. Case study: list multiplicationList multiplicationImplementationImplemented ListMult with this behavior in continuation calculusincludes modeling of naturals and lists with CC rulesProved correctListMult. l .r r. product l for all l ∈ ListNEmpirical evidence of efficiencyListMult. [4,0,6] .r r. 0 in 10 stepsListMult. [4,2,6] .r r. 48 in 339 stepsBram Geron (TU/e) Continuation calculus FSA colloquium 21 / 31
  44. 44. ConclusionConclusionCC is a term rewriting system in a constrained shapeCC is deterministicOnly head reductionAs a consequence,Suitable for control with continuations (exceptions)CC is similar to a subset of lambda calculusMimics running times of real programs to some degreeBram Geron (TU/e) Continuation calculus FSA colloquium 22 / 31
  45. 45. ConclusionCurrent state and future workJoint paper with Herman GeuversAccepted in proceedings of COS 2013, 24–25 JuneFuture work:Systematic translation of functional programming language to CCProve that this translation preserves semanticsType systemModel hierarchical side-effects using an extensionBram Geron (TU/e) Continuation calculus FSA colloquium 23 / 31
  46. 46. ConclusionThe EndQuestions?Bram Geron (TU/e) Continuation calculus FSA colloquium 24 / 31
  47. 47. BibliographyBibliographyBram Geron (TU/e) Continuation calculus FSA colloquium 25 / 31
  48. 48. Extra slidesExtra slidesExtra slidesBram Geron (TU/e) Continuation calculus FSA colloquium 26 / 31
  49. 49. Extra slides Relation to lambda calculusRelation to lambda calculusλ,λCCPS transformation−−−−−−−−−−−→ subset of λsubset of λλx to rules∗−−−−−−−−−−−−−−−−−−−−−−unfold†rules to λxCC∗ λx to rules: involves a supercombinator transformation† Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic referencesCatchphraseCC is more limited than λ,thus more suitable to model continuationsBram Geron (TU/e) Continuation calculus FSA colloquium 27 / 31
  50. 50. Extra slides Relation to lambda calculusRelation to lambda calculusλ,λCCPS transformation−−−−−−−−−−−→ subset of λsubset of λλx to rules∗−−−−−−−−−−−−−−−−−−−−−−unfold†rules to λxCC∗ λx to rules: involves a supercombinator transformation† Unfold rules to λx: first apply a fixed-point elimination to eliminate cyclic referencesCatchphraseCC is more limited than λ,thus more suitable to model continuationsBram Geron (TU/e) Continuation calculus FSA colloquium 27 / 31
  51. 51. Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yAdd.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. 52. Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yAdd.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. 53. Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yWhat can we feed to Add?ZeroS.(··· .(S.Zero)···)Something else?Bram Geron (TU/e) Continuation calculus FSA colloquium 29 / 31
  54. 54. Extra slides Interfaces, not pattern matchingNatural numbersSlightly similar to lambda calculusZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yWhat can we feed to Add?ZeroS.(··· .(S.Zero)···)Something else? Yes!Bram Geron (TU/e) Continuation calculus FSA colloquium 29 / 31
  55. 55. Extra slides Interfaces, not pattern matchingNatural numbersCompatible naturalsZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yWe define when a term t represents natural number n.1 t represents 0 if ∀z,s : t.z.s zInformally: t “behaves the same as” Zero2 t represents n +1 if ∀z,s : t.z.s s.q, and q represents nInformally: t “behaves the same as” S.qWith this, we can define LazyFact such that LazyFact.x represents (x!).(Omitted.)Bram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
  56. 56. Extra slides Interfaces, not pattern matchingNatural numbersCompatible naturalsZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yWith 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. 57. Extra slides Interfaces, not pattern matchingNatural numbersCompatible naturalsZero.z.sdef−→ zS.x.z.sdef−→ s.xAdd.r.x.ydef−→ y.(r.x).(Add.r.(S.x))Algorithm:x +0 = xx +S(y) = S(x)+yWith 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 namesCall-by-value / eager: calculate result, fill in in continuationCall-by-name / lazy: compatible with Sn.Zero but delayedcomputationBram Geron (TU/e) Continuation calculus FSA colloquium 30 / 31
  58. 58. AppendixIdeasEfficient te compileren?OUTLOOKBram Geron (TU/e) Continuation calculus FSA colloquium 31 / 31

×