Papers
Topics
Authors
Recent
Search
2000 character limit reached

Monadic Reflection in CBPV

Updated 2 April 2026
  • Monadic Reflection is a programming abstraction that separates pure values from effectful actions within the call-by-push-value framework.
  • It employs explicit reflection and reification operators to control user-defined monads and manage computational effects effectively.
  • The λ-mon calculus formalizes this approach through extended syntax, operational semantics, and a rigorous type-and-effect system.

Monadic reflection is a programming abstraction for user-defined computational effects, introduced and analyzed within the context of the call-by-push-value (CBPV) paradigm. It provides a discipline for effectful computations by separating pure values from effectful actions, enabling fine-grained control over the introduction and elimination of user-specified monads via explicit operators for reflection and reification. The monadic reflection calculus λ-mon, as developed by Forster, Kammar, Lindley, and Pretnar, formalizes this approach by extending CBPV with monad definitions, and new primitives for embedding computations into, and extracting them from, monadic contexts (Forster et al., 2016).

1. Formal Syntax and Monad Definitions

The λ-mon calculus extends the CBPV core syntax (values VV, computations MM) with three new forms:

  1. Monad-definition form: TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots, where x:αx : \alpha, y:Tαy : T\,\alpha, f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta are bound in NuN_u (the unit clause for return) and NbN_b (the bind clause for monadic composition). The monad definition binds a fresh type variable α\alpha, specifying the required algebraic structure for TT.
  2. Reflection: MM0, embedding an MM1-computation into the monad MM2.
  3. Reification: MM3, extracting a MM4-computation back into an MM5-computation.

Thus, the grammar is:

MM6

This expressive syntax enables user-defined monads whose return and bind are specified operationally.

2. Operational Semantics

The operational semantics of λ-mon is formulated by extending CBPV’s MM7-reductions with rules for reflect and reify, using evaluation contexts MM8 and hoisting contexts MM9 (up to the nearest reify):

  • Reflection:

TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots0

This rule simply ‘opens’ a reflection, delegating to the underlying computation.

  • Reification over Return:

TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots1

A reify over a returned value invokes the unit clause of the monad definition.

  • Reification over a Suspended Reflect:

TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots2

Here, a reify over a reflected computation invokes the bind clause, passing the sub-continuation as TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots3.

These operational rules provide direct and local reasoning about the interaction between computational effects and user-defined monads.

3. Type-and-Effect System

The type-and-effect discipline of λ-mon decorates each computation type with an effect, logically modeled as an ordered stack of monads. The kinding and typing judgments are:

TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots4

Key typing rules include:

  • (Define): Ensures that TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots5 and TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots6 implement a monad instance for TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots7 over an effect stub TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots8.
  • (Reflect): TxNuyfNb whereT\,x\,N_u\,y\,f\,N_b\ \text{where}\,\ldots9
  • (Reify): x:αx : \alpha0

This system enables compositional type checking for computations with complex effect stacks.

4. Set-Theoretic Denotational Semantics

The denotational semantics interprets each effect stack x:αx : \alpha1 as a set-theoretic monad x:αx : \alpha2 and each computation type x:αx : \alpha3 as the x:αx : \alpha4–algebra x:αx : \alpha5. Monad types x:αx : \alpha6 are interpreted as x:αx : \alpha7. The semantics for the new forms is:

x:αx : \alpha8

where x:αx : \alpha9 is the y:Tαy : T\,\alpha0–algebra structure of y:Tαy : T\,\alpha1.

Soundness and adequacy theorems hold:

  • If y:Tαy : T\,\alpha2 and y:Tαy : T\,\alpha3, then y:Tαy : T\,\alpha4.
  • If y:Tαy : T\,\alpha5 are closed of ground type y:Tαy : T\,\alpha6 and y:Tαy : T\,\alpha7, then y:Tαy : T\,\alpha8.

5. Macro-Translation from Algebraic Effect Handlers

A macro-translation from the calculus of algebraic effect handlers (EFF) into λ-mon demonstrates the expressive power of monadic reflection. This translation fixes a continuation monad y:Tαy : T\,\alpha9 with:

f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta0

Given a handler term, the translation is:

f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta1

Correctness: This translation simulates the operational behavior of algebraic handlers up to a finite number of f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta2-steps.

Typeability: In monomorphic λ-mon, this translation does not type-check due to the polymorphism of handlers in EFF. Introducing first-class quantified (polymorphic) operations restores typeability, enabling a uniform expressive correspondence.

6. Meta-Theoretic Properties

The λ-mon calculus enjoys fundamental meta-theoretic properties:

  • Safety: For f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta3, either f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta4, or f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta5 and f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta6.
  • Termination: For every proper closed f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta7, there is no infinite reduction sequence, and eventually f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta8 uniquely.
  • Soundness: If f:Tα(αTβ)Tβf : T\,\alpha \to (\alpha \to T\,\beta) \to T\,\beta9, then NuN_u0.
  • Adequacy: If NuN_u1 are closed, ground-type computations in the identity monad, and NuN_u2, then NuN_u3.

These properties guarantee the operational reliability, semantic faithfulness, and contextual equivalence for effectful computations modeled in λ-mon (Forster et al., 2016).

7. Expressive Power and Limitations

Felleisen's notion of macro translation establishes that monadic reflection, effect handlers, and delimited control (without answer-type modification) can macro-express each other, subject to typeability constraints. However, using the set-theoretic denotational semantics for λ-mon, it is shown that effect handlers cannot be macro-expressed while preserving typeability either by monadic reflection or delimited control. This demonstrates precise boundaries in the expressive power of these abstractions and highlights the sensitivity of their relative expressiveness to language features such as type polymorphism (Forster et al., 2016).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Monadic Reflection.