an introduction to call-by-push-value
TRANSCRIPT
An introduction to call-by-push-value calculus
H Koba
Overview of this talk• (1) Introduction• CbPV• Embedding CbV and CbN strategy in the same system
• (2) Semantics• CbV, CbN’s semantics using monads• CbPV’s semantics, using EM adjunction
Introduction• Types and
terms• [Levy, 2016]
(p. 3)
Introduction• Computations with
side effects• [Levy, 2016]
(p. 8)• Behavior of
constructs depends on the evaluation strategy• CbV, CbN, …
Introduction• CbV strategy
[Levy, 2016](p.7)• Arguments are
evaluated before substitution
Introduction• CbN strategy
[Levy, 2016](p.6)• Substitutions
occur before evaluating arguments
Introduction• How can we handle them in a single calculus?• Need to control evaluation order• Call-by-push-value calculus• distinction between “values” and “computations”
• Values: what do not need evaluation• Computations: what need evaluation
Introduction
• Call-by-push-value calculus [Levy, 2016] (p. 30)• Computation types are underlined
Introduction• [Levy, 2016] (p. 32)• return and to• like Haskell’s return
and >>=• thunk and force• No counterparts in
Haskell
Introduction• [Levy, 2016] (p. 37)• Embedding of CbV to
CbPV• In function
application, N is evaluated first
Introduction• [Levy, 2016] (p. 38)• Embedding of CbN to
CbPV• In function
application, evaluation of N is delayed (until the thunk is evaluated)
Summary• We have a calculus call-by-push-value• We have embeddings of CbV and CbN to CbPV
Semantics• (Denotational) semantics of pure typed lambda calculus is CCC (like
Sets)• Types -> objects, terms -> arrows
• , • Semantics of is
• What about non-pure computations?• Use monads to define denotational semantics• CbV and CbN need different categories
• CbV -> Kl(T), CbN -> EM(T)
Semantics• CbV’s semantics: Kl(T)• Due to Moggi (1988)
• Figure from [Levy, 2016] (p. 15)• Types -> objects in Kl(T) =
objects in C• Terms -> arrows in Kl(T) =
Kleisli arrows
Semantics• CbN’s semantics: EM(T)• Eilenberg-Moore category
• Figure from [Levy, 2016] (p. 29)• Types -> objects in EM(T) =
EM algebras• Terms -> An arrow (in C) for
some EM algebra
Semantics• CbPV’s semantics: The adjunction • Value -> object in C• Computation -> object in EM(T) (Eilenberg-Moore algebra)• Embedding of CbV and CbN preserves semantics:• Recall in CbV becomes in CbPV• This is isomorphic to !
• is a limit, so it is preserved by (right adjoint of )
Semantics• and are adjoint functors• Recall: ([Levy, 2016] (p. 30))
Summary• Embedding of CbV and CbN preserves semantics• Monad is decomposed into adjunction
References• [Levy, 2016] P.B.Levy, A tutorial on call-by-push-value (2016)
https://www.cs.bham.ac.uk/~pbl/papers/cbpvefftt.pdf • It describes denotational semantics of CbV and CbN first, then introduces
CbPV using them.
• [Levy, 1999] P.B.Levy. Call-By-Push-Value: A Subsuming Paradigm (Extended Abstract) (1999)• [Moggi, 1988] E. Moggi, Computational lambda-calculus and monads
(1988)