- 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 T is defined as TA=[R]→(A⊗[R]), where [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 δ:A→TI, interpreted as an effectful erasure map. Exception handling is modeled via a central type E 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.