Saved in:
Bibliographic Details
Main Authors: Plotkin, Gordon, Xie, Ningning
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2504.03890
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916675081732096
author Plotkin, Gordon
Xie, Ningning
author_facet Plotkin, Gordon
Xie, Ningning
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2504_03890
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Handling the Selection Monad (Full Version)
Plotkin, Gordon
Xie, Ningning
Programming Languages
Logic in Computer Science
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.
title Handling the Selection Monad (Full Version)
topic Programming Languages
Logic in Computer Science
url https://arxiv.org/abs/2504.03890