Intermediate language
In programming language theory, call-by-push-value (CBPV) is an intermediate language that embeds the call-by-value (CBV) and call-by-name (CBN) evaluation strategies. CBPV is structured as a polarized λ-calculus with two main types, "values" (+) and "computations" (-). Restrictions on interactions between the two types enforce a controlled order of evaluation, similar to monads or CPS. The calculus can embed computational effects, such as nontermination, mutable state, or nondeterminism. There are natural semantics-preserving translations from CBV and CBN into CBPV. This means that giving a CBPV semantics and proving its properties implicitly establishes CBV and CBN semantics and properties as well. Paul Blain Levy formulated and developed CBPV in several papers and his doctoral thesis.
Definition.
The CBPV paradigm is based on the slogan "a value is, a computation does". One complication in the presentation is distinguishing type variables ranging over value types from those ranging over computation types. This article follows Levy in using underlines to denote computations, so formula_1 is an (arbitrary) value type but formula_2 is a computation type. Some authors use other conventions, such as distinct sets of letters.
The exact set of constructs varies by author and desired use for the calculus, but the following constructs are typical:
A program is a closed computation of type formula_16, where formula_15 is a ground ADT type.
Complex values.
Expressions such as codice_18 make sense denotationally. But, following the rules above, codice_19 can only be encoded using pattern-matching, which would make it a computation, and therefore the overall expression must also be a computation, giving codice_20. Similarly, there is no way to obtain codice_21 from codice_22 without constructing a computation. When modelling CBPV in the equational or category theory, such constructs are indispensable. Levy therefore defines an extended IR, "CBPV with complex values". This IR extends let-binding to bind values within a value expression, and also to pattern-match a value with each clause returning a value expression. Besides modelling, such constructs also make writing programs in CBPV more natural.
Complex values complicate the operational semantics, in particular requiring an arbitrary decision of when to evaluate the complex value. Such a decision has no semantic significance because evaluating complex values has no side effects. Also, it is possible to syntactically convert any computation or closed expression to one of the same type and denotation without complex values. Therefore, many presentations omit complex values.
Translation.
The CBV translation produces CBPV values for each expression. A CBV function codice_1 : formula_22 is translated to codice_24 : formula_23. A CBV application codice_25 : formula_15 is translated to a computation codice_26 of type formula_16, making the order of evaluation explicit. A pattern match codice_17 is translated as codice_28. Values are wrapped with codice_29 when necessary, but otherwise remain unmodified. In some translations, sequencing may be required, such as translating codice_30 to codice_31.
The CBN translation produces CBPV computations for each expression. A CBN function codice_1 : formula_26 translates unaltered, codice_33 : formula_27. A CBN application codice_25 : formula_28 is translated to a computation codice_35 of type formula_29. A pattern match codice_17 is translated similarly to CBN as codice_37. ADT values are wrapped with codice_29, but codice_39 and codice_40 are also necessary on internal structure. Levy's translation assumes that codice_41, which does indeed hold.
It is also possible to extend CBPV to model call-by-need, by introducing a codice_42 construct that allows visible sharing. This construct has semantics similar to codice_43, except that with the codice_44 construct, the thunk of codice_7 is evaluated at most once.
Modifications.
Some authors have noted that CBPV can be simplified, by removing either the U type constructor (thunks) or the F type constructor (computations returning values). Egger and Mogelberg justify omitting U on the grounds of streamlined syntax and avoiding the clutter of inferable conversions from computations to values. This choice makes computation types a subset of value types, and it is then natural to expand function types to a full function space between values. They term their calculus the "Enriched Effects Calculus". This modified calculus is equivalent to a superset of CBPV via a bidirectional semantics-preserving translation. Ehrhard in contrast omits the F type constructor, making values a subset of computations. Ehrhard renames computations to "general types" to better reflect their semantics. This modified calculus, the "half-polarized lambda calculus", has close connections to linear logic. It can be translated bidirectionally to a subset of a fully-polarized variant of CBPV.
References.
 ;templatestyles src="Reflist/styles.css" / ;