arXiv:2610.23023cs.PLOct 2026

Manuscript Offprint

arXiv:2610.23023

Arbitrary Functors as Modalities in a Linear Calculus

Jean-Philippe Bernardy, Andreas Abel

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

Abstract

We study modalities in the linear lambda calculus, by interpreting them as endofunctors in monoidal closed categories. We support functors that do not distribute over products, including (co)monads. We also support arbitrary natural transformations as conversion between modalities. We provide a generic categorical semantics, which we then specialise to a sound and complete resource semantics. We use this resource semantics to derive normalisation by evaluation. Along the way, we describe several applications of such models. This work aims at providing a foundation for future programming languages with modalities. The paper is backed by a mechanisation in Agda.

1 Introduction

Modalities, rooted in modal logic, provide a formal framework for expressing notions of necessity, possibility, and other modal operators. In programming languages they can be used to model resource usage, concurrency, effects and coefficients, and security constraints [12, 19, 30, 32, 34]. While the term grades is more common in the programming community, we use the word modalities consistently throughout this paper.

Modalities are typically assumed to form a preordered, ring-like structure [2, 9]. Such a structure is sufficiently general to accommodate all of the applications mentioned above, which makes it tempting to unify them within a single system. However, the ring structure imposes (1) distributivity p(q+r)=pq+prp(q + r) = pq + pr and (2) that modality conversion is computationally irrelevant, i.e. there is a single interpretation of the preorder relation p⪯qp \preceq q. Our starting observation is that these two assumptions break down when one pushes the generic system to its limits.

Consider first distributivity. As we see below (Lemma 4.4), distributivity corresponds to modalities having the structure of (op)lax monoidal functors; meaning that there are these conversions:

Figure

But even commonplace effects such as the writer monad are not lax unless the payload is itself a monoid. Furthermore, if one simultaneously cares about resource usage, the underlying language may be linear, and then even the reader monad is not always lax. 1^{1}

1^{1}Indeed, laxity of the reader monad readerRA=R→A\boxed{\text{reader}_R} A = R \to A requires ψ2:(R→A)⊗(R→B)→R→(A⊗B)\psi_2 : (R \to A) \otimes (R \to B) \to R \to (A \otimes B), which cannot be realised unless RR is a comonoid; and not all types are comonoids in a linear language.

DRAFT PAPER UNDER REVIEW

Jean-Philippe Bernardy and Andreas Abel

Regarding the second point, assuming that there is a single possible conversion p⪯qp \preceq q between modalities p and q may be reasonable if there is a single kind of effect, or if they do not interact. [2, 32] This breaks down also if one considers data structures as modalities. In such a case a modality conversion is a reshaping of the structure, and such conversions are not determined by their type.

Our goal is to study type-systems where modalities are not necessarily distributive and where conversion carries computational content.

References (9)