arXiv:2608.27798cs.PLAug 2026

Manuscript Offprint

arXiv:2608.27798

Cambria: Resource Abstraction for Parametrized Algebraic Effects and Handlers

Jack Liell-Cock, Sam Staton

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

JACK LIELL-COCK, University of Oxford, United Kingdom

SAM STATON, University of Oxford, United Kingdom

The algebraic effects and handlers paradigm separates the concerns of the interface and implementation of computational effects in programming languages. We present CAMBRIA, a language that extends this framework to the parametrized setting. Effect signatures may use abstract parameter types that are instantiated by the handler along with the operation implementations. Parameters abstract over resources, such as memory locations or thread IDs, permitting algebraic effects to encode dynamic allocation. They are first-class in the type system but erased at runtime, requiring no coercions or type-directed reduction.

We prove parametricity via a step-indexed logical relation, formalizing the abstraction guarantee provided by parametrized handlers. We also establish type safety and classify the annotations needed for completeness of the type inference algorithm. We demonstrate CAMBRIA's practicality with a working implementation and provide examples including local state, Pólya's urn, and concurrent thread management. The last is a parametrized effect whose abstract thread IDs are shared between concurrent computations, going beyond standard instances. CAMBRIA is the first calculus with user-defined resource-allocating effects that guarantees, via parametricity, that client code cannot depend on how a handler represents its resources.

CCS Concepts: • Theory of computation → Control primitives; Type theory; Abstraction; Operational semantics; • Software and its engineering → Functional languages.

Additional Key Words and Phrases: algebraic effects, handlers, parametricity, logical relations, resource abstraction, type inference

1 Introduction

Algebraic effects and handlers [31] provide a principled approach to programming with side effects. A computation performs abstract operations such as reading state or spawning a thread, and a handler gives these operations meaning by supplying an implementation. This separation of interface from implementation has made algebraic effects an increasingly popular foundation for effect systems in both research and practice [4, 17, 22, 25, 36].

An effect’s interface often mentions types that the client uses but should never inspect. The underlying representation is the handler’s choice alone. Local state is the classic example. Client code may allocate memory locations, and read and write through them, but it should never need to know how a location is represented. For example, a location could be an index in a list, a unique name in a map, or an opaque token from the runtime. Committing the client to a concrete representation up front buys it nothing and forces unnecessary bookkeeping. Moreover, by keeping the locations abstract, the client cannot forge new ones, inspect them for equality, or perform arithmetic on them, except through the operations the interface provides. Thus, abstraction also provides a safety guarantee.

We present CAMBRIA, a language that extends algebraic effects and handlers to the parametrized setting. Formally, parametrized handlers are derived from the theory of parametrized algebraic theories (PATs) [37, 38], which extend classic algebraic theories with the ability of operators to bind and use abstract parameters in their arguments, denoting resource allocation and usage. Then a model of the theory, or a handler, instantiates the parameter as a type, as well as interpreting the operations. This generalization was introduced to handle the problem of instances of effects, where a computational effect may dynamically allocate resources at runtime, such as new memory

Authors' Contact Information: Jack Liell-Cock, University of Oxford, Oxford, United Kingdom, jack.liell-cock@cs.ox.ac.uk; Sam Staton, University of Oxford, Oxford, United Kingdom, sam.staton@cs.ox.ac.uk.

1:2

Jack Liell-Cock and Sam Staton

locations in local state. Instances of effects are a leading case for parametrized handlers, but a parameter is more generally any abstract type that an operation introduces and a handler instantiates. We demonstrate that parametrized handlers, as the operationalization of PATs, enable idiomatic implementations of diverse effects and parameters ( §2.1–2.3§2.1–2.3).

One approach to instances is to represent each as a concrete object in the program. Eff originally provided first-class instances in this way [4], but later removed them, and subsequent calculi recovered instances as dynamically allocated labels [7, 12], first-class names [45], or capabilities [8]. The drawback of these approaches is that either the resources are not first-class, or the representation is fixed and imposed on the client. CAMBRIA’s alternative approach to this problem separates the concerns of dispatch and instances. That is, a single handler handles all instances of the same effect, with the operators encoding an interface to multiple instances. For example, with local state, rather than having multiple copies of the !get and !set operators, we have an additional !ref operator that creates a new memory location that becomes an argument to !get and !set.

Effects such as dynamically threaded concurrency [18] and code jumps [15] go beyond independent instances. Parameters are shared and used to coordinate different sub-computations. This motivates a single handler interpreting all instances, rather than a witness distinguishing each one, and CAMBRIA provides this while keeping the parameters abstract. In the concurrency example, the effect operations encode POSIX-like fork and wait. Forking dynamically spawns a thread, the reference to which is an abstract thread ID that other processes can wait on. The ability to instantiate the abstract thread ID in the parametrized handler means that each scheduler implementation remains self-contained and simple. In §2.3, we demonstrate this with three different handlers implementing child-biased scheduling, parent-biased scheduling, and dependency diagnostics.

The key method underlying CAMBRIA is that parametrized handlers decompose into classic handlers and existential types. This lets the surface language stay ergonomic while the metatheory reduces to standard, modular pieces. The main result, parametricity, then gives representation independence for effects with dynamic resources without keeping track of allocation. The decomposition also eases adoption since a language that already provides effect handlers and existential types, such as OCaml 5 [36], can support parametrized handlers with little new core machinery. The addition is moreover backwards compatible since a handler with no parameters is exactly a classic handler.

In particular, we make the following contributions:

(1) Language design. We present CAMBRIA, a core calculus combining algebraic effect handlers, parameter variables, let-polymorphism, and general recursion, and establish type safety ( §2−3\S2-3).

(2) Parametricity. We prove a parametricity theorem via a step-indexed logical relation ( §4§4). This rests on an elaboration result ( §4.3§4.3) that shows parametrized handlers decompose into classic handlers and existential types.

(3) Type inference. We establish an annotation completeness result ( §5§5) that states that it suffices to annotate only operations with arities mentioning abstract parameter types. All other types, including polymorphic ones, are inferred.

(4) Expressiveness. We demonstrate that CAMBRIA can express parametrized effects with abstraction guarantees that prior work cannot, including concurrent thread management from recent work on dynamic threads [18]. We provide an implementation with runnable examples ( §2§2).

All results novel to CAMBRIA are mechanized in the Rocq prover, relying only on functional extensionality.

1:3

References (45)