SlideShare a Scribd company logo
1 of 32
Download to read offline
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Axiomatizing Subtyped Delimited
Continuations
Marek Materzok
Institute of Computer Science, University of Wroclaw
CSL 2013
Sep 4, 2013
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Structure of the talk
Short introduction to continuations
Introduction to shift0/$ operators
The axioms
The proof method
The typed version
Conclusion
This is a continuation of our previous work (ICFP’11,
APLAS’12).
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
What are continuations?
Continuations are representations of the rest of the
program execution.
Control operators are a means of altering a program’s
control flow.
They can be thought of as capturing and restoring the
program’s control stack, making continuations first
class.
The operator call/cc, which captures ,,full”
continuations, is well known and implemented in e.g.
Scheme and SML/NJ.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Evaluation contexts
Evaluation context is a ,,term with a hole”:
if sq(2) = 4 then 1 else 0
cyan part – evaluation context
It is a formal representation of the continuation.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Partial evaluation contexts
One can consider partial contexts:
if sq(2) = 4 then 1 else 0
Partial context is a prefix of the full context.
cyan part – evaluation context
yellow part – partial evaluation context
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Delimited control operators
They allow to reify partial contexts as functions, just as
call/cc reifies entire contexts.
Examples are Felleisen’s control/prompt and Danvy and
Filinski’s shift/reset.
Delimited control has lots of applications, including
asynchronous I/O, representing monads, Web
programming, mobile code, linguistics, and so on.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Delimited control operators
Delimited control operators usually come in pairs:
the delimiter, which marks where a context begins,
capture operator, which reifies the context up to the
dynamically nearest delimiter.
Example:
1 + 2 + Sf.f(f 3)
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Delimited control operators shift/reset
The most known and well explored delimited control
operators.
The shift operator captures the context up to (and
including) the nearest delimiter and resumes execution
in an empty context.
1 + 2 ∗ Sf. 3 + Sg.f(g 4)
The term above evaluates to 15: f gets the yellow context,
g gets the cyan one. Notice the “implicit” delimiter created
by a shift.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Delimited control operators shift0/reset0
A variant of shift/reset operators (also by Danvy and
Filinski).
When shift0 executes, the execution resumes in the
surrounding context.
This allows the shift0 operator to “reach” beyond the
nearest surrounding delimiter.
1 + 2 + 3 + S0f.S0g.f (g (g 4))
The term above evaluates to 12. (f gets the
yellow context , g gets the cyan one .)
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Delimited control operators shift0/$
A variant of shift0/reset0 operators, inspired by Kiselyov
and Shan’s work (TLCA’07).
The $ operator is a delimiter with a “chain link” to a
function which is executed in place (not inside!) of the
delimiter when the delimited term evaluates completely.
(λx.x ∗ 2) $ (λx.x + 1) $ 1 + S0f.S0g.f (g 2)
Evaluates to 6. (f gets the yellow context , g gets the
cyan one .)
Reading tip: the $ operator is right-associative, binds weaker
than every other binary operator, but stronger than λ.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Bigger example (shift0/$)
(λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1
The term above evaluates to 14:
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Bigger example (shift0/$)
(λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1
→(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1)
The term above evaluates to 14:
g gets the yellow context , which gets applied to 1,
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Bigger example (shift0/$)
(λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1
→(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1)
→(λx.x + 2) $ 2 ∗ (S0f.f (f 2))
The term above evaluates to 14:
g gets the yellow context , which gets applied to 1,
y gets the value 2,
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Bigger example (shift0/$)
(λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1
→(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1)
→(λx.x + 2) $ 2 ∗ (S0f.f (f 2))
→(λy.(λx.x + 2) $ 2 ∗ y) ((λy.(λx.x + 2) $ 2 ∗ y) 2)
The term above evaluates to 14:
g gets the yellow context , which gets applied to 1,
y gets the value 2,
f gets the cyan context joined with 2 ∗ ,
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Bigger example (shift0/$)
(λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1
→(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1)
→(λx.x + 2) $ 2 ∗ (S0f.f (f 2))
→(λy.(λx.x + 2) $ 2 ∗ y) ((λy.(λx.x + 2) $ 2 ∗ y) 2)
→(λy.(λx.x + 2) $ 2 ∗ y) 6 → 14
The term above evaluates to 14:
g gets the yellow context , which gets applied to 1,
y gets the value 2,
f gets the cyan context joined with 2 ∗ ,
f (f y) gets evaluated.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
CPS semantics
The control operators can be interpreted in the lambda
calculus. This makes the continuations explicit.
x = λk.k x
λx.e = λk.k (λx. e )
e1 e2 = λk. e1 (λv1. e2 (λv2.v1 v2 k))
S0x.e = λx. e
e = e (λx.λk.k x)
e1 $ e2 = λk. e1 (λv1. e2 v1 k)
This interpretation is consistent with the operational view
presented in previous slides: e1 → e2 implies e1 =βη e2 .
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
The goal
The operational view is not complete with respect to the
CPS semantics. For example:
λf.(λx.x) $ 2 + f 1
=βη λk.k (λf.f 1 (λx.λk.k (2 + x)))
=βη λf.(λx.2 + x) $ f 1
But there is no way to equalize the two terms using only
operational rules.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
The goal
The operational view is not complete with respect to the
CPS semantics. For example:
λf.(λx.x) $ 2 + f 1
=βη λk.k (λf.f 1 (λx.λk.k (2 + x)))
=βη λf.(λx.2 + x) $ f 1
But there is no way to equalize the two terms using only
operational rules.
The goal: find a finite set of equational axioms defined on
the terms of shift0/reset0 (or shift0/$) such that
e1 =ax e2 iff e1 =βη e2
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
The axioms for shift0/reset0
(λx.e) v = e{v/x}
λx.v x = v x ∈ FV(v)
(λx.E[x]) e = E[e] x ∈ FV(E)
E[S0x.e] = e{λx. E[x] /x} x ∈ FV(E)
v = v
S0k. (λx.S0z.k x) e = e k ∈ FV(e)
(λx.S0k. e1 ) e2 = (λx.e1) e2 k ∈ FV(e1)
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
The axioms for shift0/$
(λx.e) v = e{v/x}
S0x.x $ e = e x ∈ FV(e)
λx.v x = v x ∈ FV(v)
v $ S0x.e = e{v/x}
v1 $ v2 = v1 v2
v $ E[e] = (λx.v $ E[x]) $ e
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Proving completeness
Proving soundness is easy. What about completeness?
Proof for shift/reset: uses a restricted grammar for the
target terms with six syntactic categories and an inverse
translation (Kameyama and Hasegawa, ICFP’03).
Sabry introduced a technique for proving completeness
for various control operators, which involves an
intermediate language. However, the technique was not
successfully applied for shift/reset.
But it worked very well for shift0/$!
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Taking care of shift0/reset0
The shift0/reset0 operators are of equal expressive
power as shift0/$ (APLAS’12):
e ≈ (λx.x) $ e
e1 $ e2 ≈ (λw. (λv.S0k.w v) e2 ) e1
(I will be using e as a shorthand for (λx.x) $ e)
It can be proved that the axioms for shift0/reset0 are
sound and complete if and only if the axioms for
shift0/$ are sound and complete.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Opaque CPS
Opaque CPS translation is an abstract version of the
CPS translation:
x o = get k.k x
λx.e o = get k.k (λx. e o)
e1 e2 o = get k.send (λv1.
send (λv2.send k (v1 v2)) e2 o) e1 o
Uses abstract control operators (get and send), which
have semantics consistent with β and η-conversions, for
continuation passing:
send v get x.e =op e{v/x}
get x.send x e =op e x ∈ FV(e)
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
CGS translation
The opaque CPS translation with the get and send
operators implemented using some control operators is
called a continuation-grabbing style (CGS) translation.
The fact that CGS and CPS are both instances of
opaque CPS can be used for proving completeness.
Can we find a CGS translation for shift0/$?
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
CGS translation
The opaque CPS translation with the get and send
operators implemented using some control operators is
called a continuation-grabbing style (CGS) translation.
The fact that CGS and CPS are both instances of
opaque CPS can be used for proving completeness.
Can we find a CGS translation for shift0/$?
get x.e =def S0x.e
send e1 e2 =def e1 $ e2
It’s that simple!
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
CGS translation for shift0/$
We get the following translation:
x g = S0k.k x
λx.e g = S0k.k (λx. e g)
e1 e2 g = S0k.(λv1.(λv2.k $ v1 v2) $ e2 g) $ e1 g
S0x.e g = S0x. e g
e1 $ e2 g = S0k.(λv1.k $ v1 $ e2 g) $ e1 g
e1 =g e2 implies e1 =ax e2;
e g =ax e;
therefore, if e1 g =g e2 g, then e1 =ax e2.
Completeness follows easily, with a minor hurdle.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Type system for shift0
There are expressive and elegant type systems for both
shift0/reset0 (ICFP’11) and shift0/$ (APLAS’12).
The type systems track how the terms manipulate their
contexts using effects. In particular, it distinguishes
effect-free terms from effectful ones.
An important part of the type systems, which gives
them their expresiveness, is subtyping. It allows to use
effect-free terms in contexts permitting effects. (This is
a simplification.)
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Proofs in the typed setting
The proofs can be adapted for the typed setting.
In the adapted proofs, the subtyping is eliminated at the
CGS stage: the CGS terms are fully explicit.
The typed axioms are more permissive than the untyped
ones: value restriction is replaced by purity restriction.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
K&H axioms in the typed setting
The shift/reset operators can be embedded in
shift0/reset0:
Sx.e =def S0x. e
Using this embedding, the axioms of Kameyama and
Hasegawa are not validated in the untyped setting.
The type system for shift/reset by Danvy and Filinski
can be embedded into the type system for shift0/reset0.
In the image of this embedding, the axioms of
Kameyama and Hasegawa are valid.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
K&H axioms in the untyped setting
There is a different embedding of shift/reset in shift0/$:
Sx.e =def S0x.e{λy.S0f.S0g.(λz.g $ f z) $ x y/x}
e =def S0f.S0g.(λx.g $ f x) $ e
The Kameyama and Hasegawa’s axioms are valid in the
untyped setting when using this embedding.
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Conclusions
The Sabry’s elegant proof method can be applied for
shift0/$.
The axioms for shift0/$ are simple and elegant.
The axioms for shift0/reset0 can be proved complete
using the axioms for shift0/$.
The proofs can be adapted to the typed version of the
languages considered.
The Kameyama and Hasegawa’s axioms for shift/reset
are validated only in the typed setting (with the folklore
interpretation of shift/reset).
Axiomatizing
Subtyped
Delimited
Continuations
Marek Materzok
Introduction
Evaluation contexts
Delimited control
Shift0/$
Axioms
Proof
Sabry’s proof method
CGS translation
Typed version
Relationship with
shift/reset
Conclusions
Thank you!
Thank you for your attention!
This work was funded by Polish NCN grant, and co-funded
by the European Social Fund.

More Related Content

Viewers also liked (10)

Tv20103 exercise 1
Tv20103 exercise 1Tv20103 exercise 1
Tv20103 exercise 1
 
evaluation
evaluation evaluation
evaluation
 
multimedia production
multimedia productionmultimedia production
multimedia production
 
Combat pestochem ppt
Combat pestochem pptCombat pestochem ppt
Combat pestochem ppt
 
Indie magazine powerpoint
Indie magazine powerpointIndie magazine powerpoint
Indie magazine powerpoint
 
question 7
question 7question 7
question 7
 
multimedia production
multimedia production multimedia production
multimedia production
 
Titas uw00202 courseoutline_sem_1_sesi_2012_2013[1]
Titas uw00202 courseoutline_sem_1_sesi_2012_2013[1]Titas uw00202 courseoutline_sem_1_sesi_2012_2013[1]
Titas uw00202 courseoutline_sem_1_sesi_2012_2013[1]
 
Aerocluster aerospace summit oct11
Aerocluster aerospace summit oct11Aerocluster aerospace summit oct11
Aerocluster aerospace summit oct11
 
Borang kaji selidik
Borang kaji selidikBorang kaji selidik
Borang kaji selidik
 

Similar to CSL 2013 "Axiomatizing Subtyped Delimited Continuations"

Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
FamiDan
 
Numerical analysis convexity, concavity
Numerical analysis  convexity, concavityNumerical analysis  convexity, concavity
Numerical analysis convexity, concavity
SHAMJITH KM
 
MetiTarski: An Automatic Prover for Real-Valued Special Functions
MetiTarski: An Automatic Prover for Real-Valued Special FunctionsMetiTarski: An Automatic Prover for Real-Valued Special Functions
MetiTarski: An Automatic Prover for Real-Valued Special Functions
Lawrence Paulson
 
Limits and continuity powerpoint
Limits and continuity powerpointLimits and continuity powerpoint
Limits and continuity powerpoint
canalculus
 
Dipso K Mi
Dipso K MiDipso K Mi
Dipso K Mi
msabou
 
Machine learning (13)
Machine learning (13)Machine learning (13)
Machine learning (13)
NYversity
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
bolovv
 

Similar to CSL 2013 "Axiomatizing Subtyped Delimited Continuations" (20)

2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster2015 CMS Winter Meeting Poster
2015 CMS Winter Meeting Poster
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
 
Numerical analysis convexity, concavity
Numerical analysis  convexity, concavityNumerical analysis  convexity, concavity
Numerical analysis convexity, concavity
 
Colloquium presentation
Colloquium presentationColloquium presentation
Colloquium presentation
 
267 handout 2_partial_derivatives_v2.60
267 handout 2_partial_derivatives_v2.60267 handout 2_partial_derivatives_v2.60
267 handout 2_partial_derivatives_v2.60
 
31A WePrep Presentation
31A WePrep Presentation31A WePrep Presentation
31A WePrep Presentation
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
MetiTarski: An Automatic Prover for Real-Valued Special Functions
MetiTarski: An Automatic Prover for Real-Valued Special FunctionsMetiTarski: An Automatic Prover for Real-Valued Special Functions
MetiTarski: An Automatic Prover for Real-Valued Special Functions
 
3.1 Functions and Function Notation
3.1 Functions and Function Notation3.1 Functions and Function Notation
3.1 Functions and Function Notation
 
logGaussianField
logGaussianFieldlogGaussianField
logGaussianField
 
Cs229 notes12
Cs229 notes12Cs229 notes12
Cs229 notes12
 
Tutorfly Review Session Math 31A
Tutorfly Review Session Math 31ATutorfly Review Session Math 31A
Tutorfly Review Session Math 31A
 
Limits and continuity powerpoint
Limits and continuity powerpointLimits and continuity powerpoint
Limits and continuity powerpoint
 
Dipso K Mi
Dipso K MiDipso K Mi
Dipso K Mi
 
Lecture co3 math21-1
Lecture co3 math21-1Lecture co3 math21-1
Lecture co3 math21-1
 
Machine learning (13)
Machine learning (13)Machine learning (13)
Machine learning (13)
 
aaoczc2252
aaoczc2252aaoczc2252
aaoczc2252
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
 
MUMS: Bayesian, Fiducial, and Frequentist Conference - Model Selection in the...
MUMS: Bayesian, Fiducial, and Frequentist Conference - Model Selection in the...MUMS: Bayesian, Fiducial, and Frequentist Conference - Model Selection in the...
MUMS: Bayesian, Fiducial, and Frequentist Conference - Model Selection in the...
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

CSL 2013 "Axiomatizing Subtyped Delimited Continuations"

  • 1. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Axiomatizing Subtyped Delimited Continuations Marek Materzok Institute of Computer Science, University of Wroclaw CSL 2013 Sep 4, 2013
  • 2. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Structure of the talk Short introduction to continuations Introduction to shift0/$ operators The axioms The proof method The typed version Conclusion This is a continuation of our previous work (ICFP’11, APLAS’12).
  • 3. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions What are continuations? Continuations are representations of the rest of the program execution. Control operators are a means of altering a program’s control flow. They can be thought of as capturing and restoring the program’s control stack, making continuations first class. The operator call/cc, which captures ,,full” continuations, is well known and implemented in e.g. Scheme and SML/NJ.
  • 4. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Evaluation contexts Evaluation context is a ,,term with a hole”: if sq(2) = 4 then 1 else 0 cyan part – evaluation context It is a formal representation of the continuation.
  • 5. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Partial evaluation contexts One can consider partial contexts: if sq(2) = 4 then 1 else 0 Partial context is a prefix of the full context. cyan part – evaluation context yellow part – partial evaluation context
  • 6. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Delimited control operators They allow to reify partial contexts as functions, just as call/cc reifies entire contexts. Examples are Felleisen’s control/prompt and Danvy and Filinski’s shift/reset. Delimited control has lots of applications, including asynchronous I/O, representing monads, Web programming, mobile code, linguistics, and so on.
  • 7. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Delimited control operators Delimited control operators usually come in pairs: the delimiter, which marks where a context begins, capture operator, which reifies the context up to the dynamically nearest delimiter. Example: 1 + 2 + Sf.f(f 3)
  • 8. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Delimited control operators shift/reset The most known and well explored delimited control operators. The shift operator captures the context up to (and including) the nearest delimiter and resumes execution in an empty context. 1 + 2 ∗ Sf. 3 + Sg.f(g 4) The term above evaluates to 15: f gets the yellow context, g gets the cyan one. Notice the “implicit” delimiter created by a shift.
  • 9. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Delimited control operators shift0/reset0 A variant of shift/reset operators (also by Danvy and Filinski). When shift0 executes, the execution resumes in the surrounding context. This allows the shift0 operator to “reach” beyond the nearest surrounding delimiter. 1 + 2 + 3 + S0f.S0g.f (g (g 4)) The term above evaluates to 12. (f gets the yellow context , g gets the cyan one .)
  • 10. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Delimited control operators shift0/$ A variant of shift0/reset0 operators, inspired by Kiselyov and Shan’s work (TLCA’07). The $ operator is a delimiter with a “chain link” to a function which is executed in place (not inside!) of the delimiter when the delimited term evaluates completely. (λx.x ∗ 2) $ (λx.x + 1) $ 1 + S0f.S0g.f (g 2) Evaluates to 6. (f gets the yellow context , g gets the cyan one .) Reading tip: the $ operator is right-associative, binds weaker than every other binary operator, but stronger than λ.
  • 11. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Bigger example (shift0/$) (λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1 The term above evaluates to 14:
  • 12. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Bigger example (shift0/$) (λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1 →(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1) The term above evaluates to 14: g gets the yellow context , which gets applied to 1,
  • 13. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Bigger example (shift0/$) (λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1 →(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1) →(λx.x + 2) $ 2 ∗ (S0f.f (f 2)) The term above evaluates to 14: g gets the yellow context , which gets applied to 1, y gets the value 2,
  • 14. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Bigger example (shift0/$) (λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1 →(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1) →(λx.x + 2) $ 2 ∗ (S0f.f (f 2)) →(λy.(λx.x + 2) $ 2 ∗ y) ((λy.(λx.x + 2) $ 2 ∗ y) 2) The term above evaluates to 14: g gets the yellow context , which gets applied to 1, y gets the value 2, f gets the cyan context joined with 2 ∗ ,
  • 15. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Bigger example (shift0/$) (λx.x + 2) $ (λy.S0f.f (f y)) $ 1 + S0g.2 ∗ g 1 →(λx.x + 2) $ 2 ∗ ((λy.S0f.f (f y)) $ 1 + 1) →(λx.x + 2) $ 2 ∗ (S0f.f (f 2)) →(λy.(λx.x + 2) $ 2 ∗ y) ((λy.(λx.x + 2) $ 2 ∗ y) 2) →(λy.(λx.x + 2) $ 2 ∗ y) 6 → 14 The term above evaluates to 14: g gets the yellow context , which gets applied to 1, y gets the value 2, f gets the cyan context joined with 2 ∗ , f (f y) gets evaluated.
  • 16. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions CPS semantics The control operators can be interpreted in the lambda calculus. This makes the continuations explicit. x = λk.k x λx.e = λk.k (λx. e ) e1 e2 = λk. e1 (λv1. e2 (λv2.v1 v2 k)) S0x.e = λx. e e = e (λx.λk.k x) e1 $ e2 = λk. e1 (λv1. e2 v1 k) This interpretation is consistent with the operational view presented in previous slides: e1 → e2 implies e1 =βη e2 .
  • 17. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions The goal The operational view is not complete with respect to the CPS semantics. For example: λf.(λx.x) $ 2 + f 1 =βη λk.k (λf.f 1 (λx.λk.k (2 + x))) =βη λf.(λx.2 + x) $ f 1 But there is no way to equalize the two terms using only operational rules.
  • 18. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions The goal The operational view is not complete with respect to the CPS semantics. For example: λf.(λx.x) $ 2 + f 1 =βη λk.k (λf.f 1 (λx.λk.k (2 + x))) =βη λf.(λx.2 + x) $ f 1 But there is no way to equalize the two terms using only operational rules. The goal: find a finite set of equational axioms defined on the terms of shift0/reset0 (or shift0/$) such that e1 =ax e2 iff e1 =βη e2
  • 19. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions The axioms for shift0/reset0 (λx.e) v = e{v/x} λx.v x = v x ∈ FV(v) (λx.E[x]) e = E[e] x ∈ FV(E) E[S0x.e] = e{λx. E[x] /x} x ∈ FV(E) v = v S0k. (λx.S0z.k x) e = e k ∈ FV(e) (λx.S0k. e1 ) e2 = (λx.e1) e2 k ∈ FV(e1)
  • 20. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions The axioms for shift0/$ (λx.e) v = e{v/x} S0x.x $ e = e x ∈ FV(e) λx.v x = v x ∈ FV(v) v $ S0x.e = e{v/x} v1 $ v2 = v1 v2 v $ E[e] = (λx.v $ E[x]) $ e
  • 21. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Proving completeness Proving soundness is easy. What about completeness? Proof for shift/reset: uses a restricted grammar for the target terms with six syntactic categories and an inverse translation (Kameyama and Hasegawa, ICFP’03). Sabry introduced a technique for proving completeness for various control operators, which involves an intermediate language. However, the technique was not successfully applied for shift/reset. But it worked very well for shift0/$!
  • 22. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Taking care of shift0/reset0 The shift0/reset0 operators are of equal expressive power as shift0/$ (APLAS’12): e ≈ (λx.x) $ e e1 $ e2 ≈ (λw. (λv.S0k.w v) e2 ) e1 (I will be using e as a shorthand for (λx.x) $ e) It can be proved that the axioms for shift0/reset0 are sound and complete if and only if the axioms for shift0/$ are sound and complete.
  • 23. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Opaque CPS Opaque CPS translation is an abstract version of the CPS translation: x o = get k.k x λx.e o = get k.k (λx. e o) e1 e2 o = get k.send (λv1. send (λv2.send k (v1 v2)) e2 o) e1 o Uses abstract control operators (get and send), which have semantics consistent with β and η-conversions, for continuation passing: send v get x.e =op e{v/x} get x.send x e =op e x ∈ FV(e)
  • 24. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions CGS translation The opaque CPS translation with the get and send operators implemented using some control operators is called a continuation-grabbing style (CGS) translation. The fact that CGS and CPS are both instances of opaque CPS can be used for proving completeness. Can we find a CGS translation for shift0/$?
  • 25. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions CGS translation The opaque CPS translation with the get and send operators implemented using some control operators is called a continuation-grabbing style (CGS) translation. The fact that CGS and CPS are both instances of opaque CPS can be used for proving completeness. Can we find a CGS translation for shift0/$? get x.e =def S0x.e send e1 e2 =def e1 $ e2 It’s that simple!
  • 26. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions CGS translation for shift0/$ We get the following translation: x g = S0k.k x λx.e g = S0k.k (λx. e g) e1 e2 g = S0k.(λv1.(λv2.k $ v1 v2) $ e2 g) $ e1 g S0x.e g = S0x. e g e1 $ e2 g = S0k.(λv1.k $ v1 $ e2 g) $ e1 g e1 =g e2 implies e1 =ax e2; e g =ax e; therefore, if e1 g =g e2 g, then e1 =ax e2. Completeness follows easily, with a minor hurdle.
  • 27. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Type system for shift0 There are expressive and elegant type systems for both shift0/reset0 (ICFP’11) and shift0/$ (APLAS’12). The type systems track how the terms manipulate their contexts using effects. In particular, it distinguishes effect-free terms from effectful ones. An important part of the type systems, which gives them their expresiveness, is subtyping. It allows to use effect-free terms in contexts permitting effects. (This is a simplification.)
  • 28. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Proofs in the typed setting The proofs can be adapted for the typed setting. In the adapted proofs, the subtyping is eliminated at the CGS stage: the CGS terms are fully explicit. The typed axioms are more permissive than the untyped ones: value restriction is replaced by purity restriction.
  • 29. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions K&H axioms in the typed setting The shift/reset operators can be embedded in shift0/reset0: Sx.e =def S0x. e Using this embedding, the axioms of Kameyama and Hasegawa are not validated in the untyped setting. The type system for shift/reset by Danvy and Filinski can be embedded into the type system for shift0/reset0. In the image of this embedding, the axioms of Kameyama and Hasegawa are valid.
  • 30. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions K&H axioms in the untyped setting There is a different embedding of shift/reset in shift0/$: Sx.e =def S0x.e{λy.S0f.S0g.(λz.g $ f z) $ x y/x} e =def S0f.S0g.(λx.g $ f x) $ e The Kameyama and Hasegawa’s axioms are valid in the untyped setting when using this embedding.
  • 31. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Conclusions The Sabry’s elegant proof method can be applied for shift0/$. The axioms for shift0/$ are simple and elegant. The axioms for shift0/reset0 can be proved complete using the axioms for shift0/$. The proofs can be adapted to the typed version of the languages considered. The Kameyama and Hasegawa’s axioms for shift/reset are validated only in the typed setting (with the folklore interpretation of shift/reset).
  • 32. Axiomatizing Subtyped Delimited Continuations Marek Materzok Introduction Evaluation contexts Delimited control Shift0/$ Axioms Proof Sabry’s proof method CGS translation Typed version Relationship with shift/reset Conclusions Thank you! Thank you for your attention! This work was funded by Polish NCN grant, and co-funded by the European Social Fund.