html5-img
1 / 267

Alexander J Summers Department of Computing Imperial College London

Natural Delimited Control A Curry-Howard Correspondence for a Canonical Classical Natural Deduction. Alexander J Summers Department of Computing Imperial College London. Overview. Interested in the extension of the Curry-Howard Correspondence to Classical Logics

garyharris
Download Presentation

Alexander J Summers Department of Computing Imperial College London

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Natural Delimited ControlA Curry-Howard Correspondence for a Canonical Classical Natural Deduction Alexander J Summers Department of Computing Imperial College London

  2. Overview • Interested in the extension of the Curry-Howard Correspondence to Classical Logics • Talk roughly in three parts... • 1. Brief introduction to Control Operators • 2. Definition of a programming calculus based on classical natural deduction • 3. How are the two related? • Talk is semi-informal: focus on intuition/explanation • Feel free to ask questions..

  3. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> n*(f rest))

  4. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> n*(f rest))

  5. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> n*(f rest))

  6. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> n*(f rest)) 

  7. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest -->if n=0 then0 else n*(f rest)) 

  8. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest -->if n=0 then0 else n*(f rest)) 

  9. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest))

  10. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) 

  11. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) 

  12. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) 

  13. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) 

  14. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l (Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) ? 

  15. Contexts and Continuations • Control operators give control over the context in which an execution takes place termcontext

  16. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))termcontext

  17. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context

  18. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context

  19. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole”

  20. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●)))

  21. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●))) E{3 * 4}= print (1 * (2 * (3 * 4)))

  22. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●))) E{3 * 4}= print (1 * (2 * (3 * 4))) • A continuation is a term representation of a context • A term with a ‘hole’ for another term

  23. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●))) E{3 * 4}= print (1 * (2 * (3 * 4))) • A continuation is a term representation of a context • A term with a ‘hole’ for another term • We represent this with a binder νover the ‘hole’

  24. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●))) E{3 * 4}= print (1 * (2 * (3 * 4))) • A continuation is a term representation of a context • A term with a ‘hole’ for another term • We represent this with a binder νover the ‘hole’ νx.print (1 * (2 * (●)))

  25. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●))) E{3 * 4}= print (1 * (2 * (3 * 4))) • A continuation is a term representation of a context • A term with a ‘hole’ for another term • We represent this with a binder νover the ‘hole’ νx.print (1 * (2 * (x)))

  26. Contexts and Continuations • Control operators give control over the context in which an execution takes place print (1 * (2 * (3 * 4)))term context • We write contexts as E{●} where ● is the “hole” E{●}= print (1 * (2 * (●))) E{3 * 4}= print (1 * (2 * (3 * 4))) • A continuation is a term representation of a context • A term with a ‘hole’ for another term • We represent this with a binder νover the ‘hole’ νx.print (1 * (2 * (x)))

  27. Control Operators • Programming constructs for functional languages • Allow the expression of “non-functional” behaviour • e.g., jumps, exceptions, loops, ... • Simplest example: A (“abort”) • Defined by: E{A M}→M • Completely discards the surrounding context print (1 * (2 * (A (3 * 4))))

  28. Control Operators • Programming constructs for functional languages • Allow the expression of “non-functional” behaviour • e.g., jumps, exceptions, loops, ... • Simplest example: A (“abort”) • Defined by: E{A M}→M • Completely discards the surrounding context print (1 * (2 * (A (3 * 4)))) → print (1 * (2 * (A 12)))

  29. Control Operators • Programming constructs for functional languages • Allow the expression of “non-functional” behaviour • e.g., jumps, exceptions, loops, ... • Simplest example: A (“abort”) • Defined by: E{A M}→M • Completely discards the surrounding context print (1 * (2 * (A (3 * 4)))) → print (1 * (2 * (A 12))) → print (1 * (2 * (A12)))

  30. Control Operators • More interesting example: C (“control”) • CM gives M explicit control over the context • Stores the context in an “escape procedure” E{CM}→Mλx.(AE{x}) • The escape procedure is passed to M • If M calls procedure with argument N, resulting term AE{N}aborts current execution and restores the context E{N} • In this way, M can “throw” values back to the context

  31. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l Cλk.k(Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) ? 

  32. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l Cλk.k(Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) ? 

  33. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l Cλk.k(Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) ? 

  34. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l Cλk.k(Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then 0 else n*(f rest)) ? 

  35. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l Cλk.k(Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then k 0 else n*(f rest)) ? 

  36. Multiplying lists of numbers.. • Exercise: write a recursive function / functional program to calculate the product of a list of numbers • Lists are defined by: l ::= [] | n:l Cλk.k(Fix f. λy.match y with [] --> 1 n:rest --> if n=0 then k 0 else n*(f rest)) 

  37. Types for Control Operators • What about types for these operators? e.g., abort • Consider the reduction rule: E{A M}→M • (A M)should have the type of the “hole” in E • M can have any type? • But, for the rule to be sound, Mmust have the type of E{A M} • Griffin (‘90): introduce special  type for “top-level” • The type of “finished computation” - M must have it Γ⊢M : B (A) Γ⊢(AM) : C

  38. Types for Control Operators • What about types for these operators? e.g., abort • Consider the reduction rule: E{A M}→M • (A M)should have the type of the “hole” in E • M can have any type? • But, for the rule to be sound, Mmust have the type of E{A M} • Griffin (‘90): introduce special  type for “top-level” • The type of “finished computation” - M must have it • Now A makes logical sense in terms of types too • corresponds with -elimination from intuitionistic logic Γ⊢M :  (A) Γ⊢(AM) : C

  39. Types for Control Operators • What about types for these operators? e.g., abort • Consider the reduction rule: E{A M}→M • (A M)should have the type of the “hole” in E • M can have any type? • But, for the rule to be sound, Mmust have the type of E{A M} • Griffin (‘90): introduce special  type for “top-level” • The type of “finished computation” - M must have it • Now A makes logical sense in terms of types too • corresponds with -elimination from intuitionistic logic Γ⊢M :  (A) Γ⊢(A M) : C

  40. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→M λx.(AE{x})

  41. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→M λx.(AE{x}) 

  42. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→M λx.(AE{x}) A 

  43. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→M λx.(AE{x}) A  B

  44. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→M λx.(AE{x}) A  B

  45. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→M λx.(AE{x}) A  B A→B

  46. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→Mλx.(AE{x}) A  B A→B

  47. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→Mλx.(AE{x}) A  B (A→B)→ A→B

  48. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→Mλx.(AE{x}) A  B (A→B)→ A→B

  49. Control Operators - types • What about the more powerful C control operator? • Recall the reduction rule: E{C M}→Mλx.(AE{x}) • Observation (Griffin): if we set B= then C can be typed as double-negation-elimination:((A→)→)→A ≡¬ ¬ A→A • Led to research into computational interpretations of classical logics.. including this talk! A  B ((A→B)→)→A (A→B)→ A→B

  50. Delimited Control Operators • So far, control operators capture entire context • A refinement to the previous ideas: delimited control • “markers” # can be placed around any subterm: # M • Only capture the context up to the enclosing # • Refines reduction behaviours:

More Related