Table of Contents
Fetching ...

Handling the Selection Monad (Full Version)

Gordon Plotkin, Ningning Xie

TL;DR

This work presents a novel integration of the selection monad with algebraic effect handlers by introducing choice continuations that expose future losses to programmer-defined operations. The λC language formalizes this design with a deterministic, progressive small-step semantics, a termination guarantee for a safe subset, and a denotational model based on augmented selection monads, establishing soundness and adequacy results. The authors provide a Haskell library and a diverse set of programming examples, including greedy strategies, optimizations, hyperparameter tuning, and two-player games, illustrating the expressiveness and practicality of loss-aware effect handling. This framework enables programmable, loss-aware selection within modular effects, with potential applications in optimization, learning, game-playing, and beyond. The approach advances the theory and practice of effect handlers by enabling explicit access to loss information through choice continuations, offering a flexible foundation for future extensions and integrations with ML and AI tooling.

Abstract

The selection monad on a set consists of selection functions. These select an element from the set, based on a loss (dually, reward) function giving the loss resulting from a choice of an element. Abadi and Plotkin used the monad to model a language with operations making choices of computations taking account of the loss that would arise from each choice. However, their choices were optimal, and they asked if they could instead be programmer provided. In this work, we present a novel design enabling programmers to do so. We present a version of algebraic effect handlers enriched by computational ideas inspired by the selection monad. Specifically, as well as the usual delimited continuations, our new kind of handlers additionally have access to choice continuations, that give the possible future losses. In this way programmers can write operations implementing optimisation algorithms that are aware of the losses arising from their possible choices. We give an operational semantics for a higher-order model language $λC$, and establish desirable properties including progress, type soundness, and termination for a subset with a mild hierarchical constraint on allowable operation types. We give this subset a selection monad denotational semantics, and prove soundness and adequacy results. We also present a Haskell implementation and give a variety of programming examples.

Handling the Selection Monad (Full Version)

TL;DR

This work presents a novel integration of the selection monad with algebraic effect handlers by introducing choice continuations that expose future losses to programmer-defined operations. The λC language formalizes this design with a deterministic, progressive small-step semantics, a termination guarantee for a safe subset, and a denotational model based on augmented selection monads, establishing soundness and adequacy results. The authors provide a Haskell library and a diverse set of programming examples, including greedy strategies, optimizations, hyperparameter tuning, and two-player games, illustrating the expressiveness and practicality of loss-aware effect handling. This framework enables programmable, loss-aware selection within modular effects, with potential applications in optimization, learning, game-playing, and beyond. The approach advances the theory and practice of effect handlers by enabling explicit access to loss information through choice continuations, offering a flexible foundation for future extensions and integrations with ML and AI tooling.

Abstract

The selection monad on a set consists of selection functions. These select an element from the set, based on a loss (dually, reward) function giving the loss resulting from a choice of an element. Abadi and Plotkin used the monad to model a language with operations making choices of computations taking account of the loss that would arise from each choice. However, their choices were optimal, and they asked if they could instead be programmer provided. In this work, we present a novel design enabling programmers to do so. We present a version of algebraic effect handlers enriched by computational ideas inspired by the selection monad. Specifically, as well as the usual delimited continuations, our new kind of handlers additionally have access to choice continuations, that give the possible future losses. In this way programmers can write operations implementing optimisation algorithms that are aware of the losses arising from their possible choices. We give an operational semantics for a higher-order model language , and establish desirable properties including progress, type soundness, and termination for a subset with a mild hierarchical constraint on allowable operation types. We give this subset a selection monad denotational semantics, and prove soundness and adequacy results. We also present a Haskell implementation and give a variety of programming examples.

Paper Structure

This paper contains 42 sections, 38 theorems, 103 equations, 11 figures.

Key Result

Lemma 3.1

Every expression has exactly one of the following five forms: (1) a value $v$ (for a unique $v$), (2) a stuck expression $K[\mathit{op}(v)]$ (for unique $K$, $\mathit{op}$, and $v$), (3) a redex $R$ (for a unique $R$), (4) $F[e]$ (for unique $F$ and $e$, with $e$ not a value or stuck), or (5) $S[e]$

Figures (11)

  • Figure 1: Terminology
  • Figure 2: Syntax of types and effects
  • Figure 4: Typing rules for $\lambda C$
  • Figure 5: Syntactical classes used for operational semantics
  • Figure 7: Big-step operational semantics rules
  • ...and 6 more figures

Theorems & Definitions (60)

  • Lemma 3.1: Expression analysis
  • Theorem 3.2
  • corollary 1
  • Lemma 3.3: Fundamental Lemma
  • Theorem 3.4: Termination
  • Theorem 3.5
  • Lemma 5.1
  • Lemma 5.2
  • Theorem 5.3: Small-step Soundness
  • Theorem 5.4: Evaluation soundness
  • ...and 50 more