Papers
Topics
Authors
Recent
Assistant
AI Research Assistant
Well-researched responses based on relevant abstracts and paper content.
Custom Instructions Pro
Preferences or requirements that you'd like Emergent Mind to consider when generating responses.
Gemini 2.5 Flash
Gemini 2.5 Flash 189 tok/s
Gemini 2.5 Pro 46 tok/s Pro
GPT-5 Medium 35 tok/s Pro
GPT-5 High 40 tok/s Pro
GPT-4o 103 tok/s Pro
Kimi K2 207 tok/s Pro
GPT OSS 120B 451 tok/s Pro
Claude Sonnet 4.5 38 tok/s Pro
2000 character limit reached

Linear effects, exceptions, and resource safety: a Curry-Howard correspondence for destructors (2510.23517v1)

Published 27 Oct 2025 in cs.PL and cs.LO

Abstract: We analyse the problem of combining linearity, effects, and exceptions, in abstract models of programming languages, as the issue of providing some kind of strength for a monad $T(- \oplus E)$ in a linear setting. We consider in particular for $T$ the allocation monad, which we introduce to model and study resource-safety properties. We apply these results to a series of two linear effectful calculi for which we establish their resource-safety properties. The first calculus is a linear call-by-push-value language with two allocation effects $\mathit{new}$ and $\mathit{delete}$. The resource-safety properties follow from the linear (and even ordered) character of the typing rules. We then explain how to integrate exceptions on top of linearity and effects by adjoining default destruction actions to types, as inspired by C++/Rust destructors. We see destructors as objects $\delta : A\rightarrow TI$ in the slice category over $TI$. This construction gives rise to a second calculus, an affine ordered call-by-push-value language with exceptions and destructors, in which the weakening rule performs a side-effect. As in C++/Rust, a ``move'' operation is necessary to allow random-order release of resources, as opposed to last-in-first-out order. Moving resources is modelled as an exchange rule that performs a side-effect.

Summary

  • The paper introduces the allocation monad and two calculi to model resource safety by integrating linear effects, exceptions, and destructors.
  • The paper develops a relaxed notion of monadic strength for exception handling in linear settings, ensuring each resource is released exactly once.
  • The paper presents categorical semantics and translations that reconcile destructors with the Curry-Howard correspondence, guiding safe language design.

Linear Effects, Exceptions, and Resource Safety: A Curry-Howard Correspondence for Destructors

Introduction and Motivation

This paper addresses the integration of linearity, computational effects, and exceptions in programming language semantics, focusing on resource safety. The central technical challenge is the lack of a general monadic strength for the exception monad in linear settings, which impedes the combination of linear resource management and control effects. The authors introduce the allocation monad to model resource management and develop two calculi: a linear call-by-push-value language with allocation effects, and an affine ordered call-by-push-value language with exceptions and destructors. The latter is inspired by C++/Rust-style destructors, providing a formal correspondence between destructors and logical erasure maps in the Curry-Howard framework.

Monads, Linearity, and Strength

The paper begins by reviewing the role of strong monads in modeling computational effects, emphasizing the importance of monadic strength for composing effectful computations. In linear logic, the cartesian product is replaced by a symmetric monoidal tensor, restricting duplication and erasure. The standard notion of monadic strength does not extend to control effects (e.g., exceptions) in linear settings, as these effects can duplicate or erase the computation context.

To address this, the authors propose a relaxed notion of strength relative to a resource modality (e.g., affine or ordered), allowing erasure but not duplication. This enables the exception monad to be strong with respect to contexts that can be erased via a coalgebra structure, but not duplicated. The key insight is that destructors—effectful erasure maps—can be used to model resource release in the presence of exceptions.

The Allocation Monad and Resource Safety

Resource management is formalized via the allocation monad, a linear state monad over lists of resources. The two primitive operations are:

  • $\New: I \to R \oplus I$ (acquire a resource or fail)
  • $\Delete: R \to I$ (release a resource)

The allocation monad TT is defined as TA=[R](A[R])TA = [R] \to (A \otimes [R]), where [R][R] is the type of resource lists. Well-typed programs in this setting satisfy strong resource-safety properties: every acquired resource is released exactly once, even in the presence of errors. In the ordered fragment (no exchange rule), resources are released in strict LIFO order; in the linear fragment, release order is arbitrary but each resource is released exactly once.

Ordered and Linear Call-by-Push-Value Calculi

The first calculus is an ordered call-by-push-value language with allocation effects. The type system enforces linearity and order, preventing resource leaks and double releases. The operational semantics is given by an abstract machine that tracks the freelist of resources. The calculus is shown to be deterministic, confluent, and enjoys subject reduction and progress.

The resource-safety properties are formally proved: in the ordered fragment, the final freelist is identical to the initial freelist; in the linear fragment, the final freelist is a permutation of the initial one.

Affine Calculus with Exceptions and Destructors

The second calculus extends the first with exceptions and destructors. Every positive type is equipped with a destructor δ:ATI\delta: A \to TI, interpreted as an effectful erasure map. Exception handling is modeled via a central type EE and a value $\NewFail: E$ thrown on allocation failure. The weakening rule (erasure) and exchange rule (move) are effectful, reflecting the semantics of C++/Rust destructors and move operations.

A translation from the affine calculus to the linear calculus is provided, preserving resource-safety properties. The translation uses shifts $\Up A = A \oplus E$ and $\Down A = A \With 1$, and defines explicit destructor and unwind operations for context management during exception propagation.

Categorical Semantics and Presheaf Model

The paper develops a categorical semantics for the ordered calculus using presheaf categories over lists of resources. The allocation monad arises from an adjunction corresponding to the right closed structure. The model supports a left strength for the exception monad when exceptions are central (resource-free) objects, corresponding to the Drinfeld center of the category.

Every object in the category has a unique destructor, but only central objects have trivial destructors. The model is affine in the sense of the calculus with destructors, but not in the usual sense of affine logic (semi-cartesian monoidal categories).

Implications and Future Directions

The formalization provides a principled foundation for resource management in programming languages, reconciling linear types and control effects. The use of destructors as effectful erasure maps enables safe resource release in the presence of exceptions, matching the semantics of C++/Rust. The approach generalizes stack-based resource management (LIFO) and supports first-class resources, including in algebraic data types and closures.

The paper highlights that contextual isomorphism fails for tensor types with destructors, as the order of destructor execution is observable. This departs from symmetric premonoidal categories and has implications for type isomorphism and program equivalence.

Future work includes:

  • Integrating copyable types via interaction of resource modalities
  • Formalizing borrowing and unique ownership in the framework
  • Extending the Curry-Howard-Lambek correspondence to ordered call-by-push-value
  • Applying the theory to formal verification and functional correctness of resource-sensitive programs (e.g., Rust typestate)

Conclusion

This work establishes a Curry-Howard correspondence for destructors, providing a rigorous foundation for resource safety in the presence of linearity and exceptions. The allocation monad and effectful erasure maps (destructors) enable precise reasoning about resource management, matching practical patterns in modern systems languages. The categorical semantics and translation results open avenues for principled language design and formal verification of resource-sensitive software.

Dice Question Streamline Icon: https://streamlinehq.com
List To Do Tasks Checklist Streamline Icon: https://streamlinehq.com

Collections

Sign up for free to add this paper to one or more collections.

Reddit Logo Streamline Icon: https://streamlinehq.com