Handling the Selection Monad (Full Version)

📅 2025-04-04
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
This paper addresses the problem that optimization decisions in programming languages overly rely on globally optimal choices, leaving programmers with insufficient control. To resolve this, we propose a mechanism supporting non-optimal, loss-aware selections. Methodologically, we introduce the monadic choice paradigm into algebraic effect handlers for the first time, designing “choice continuations” that explicitly expose potential future decision losses during effect handling—enabling programmers to define custom selection strategies based on quantitative cost information. Theoretically, we formalize the λC language with both operational and denotational semantics, rigorously proving progress, type safety, termination, and semantic adequacy and soundness. Practically, we implement the system in Haskell, integrating delimited continuations and a higher-order type system. Our contribution is the first algebraic effect system enabling programmer-directed, loss-aware choice handling, empirically validated across multiple optimization-oriented programming examples.

Technology Category

Application Category

📝 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 $lambda 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.
Problem

Research questions and friction points this paper is trying to address.

Enabling programmers to provide custom choices in selection monad
Introducing choice continuations for loss-aware optimization algorithms
Designing a language with operational and denotational semantics for selection
Innovation

Methods, ideas, or system contributions that make the work stand out.

Enriched algebraic effect handlers with choice continuations
Operational semantics for higher-order model language λC
Haskell implementation with programming examples
🔎 Similar Papers
No similar papers found.