What's in the Box: Ergonomic and Expressive Capture Tracking over Generic Data Structures (Extended Version)

📅 2025-09-09
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Scala’s original capture types inadequately track nested capabilities in generic data structures—such as the standard collections library—leading to insufficient expressiveness and poor scalability. This paper introduces System Capless, a novel foundation for capture types centered on *reachable capabilities* (rcaps): a mechanism that jointly employs existential and universal quantification over capture sets to name “contents of boxes” without exposing underlying existential types, while supporting optional explicit quantification to balance lightweight syntax with strong expressivity. We formally verify type safety and scope safety in Lean, design a type-preserving translation to ensure backward compatibility, and implement a new capture checker in Scala 3. Our approach enables zero- or low-annotation migration of the entire Scala collections library and key asynchronous programming libraries, demonstrating practicality, scalability, and minimal intrusiveness.

Technology Category

Application Category

📝 Abstract
Capturing types in Scala unify static effect and resource tracking with object capabilities, enabling lightweight effect polymorphism with minimal notational overhead. However, their expressiveness has been insufficient for tracking capabilities embedded in generic data structures, preventing them from scaling to the standard collections library -- an essential prerequisite for broader adoption. This limitation stems from the inability to name capabilities within the system's notion of box types. This paper develops System Capless, a new foundation for capturing types that provides the theoretical basis for reach capabilities (rcaps), a novel mechanism for naming "what's in the box." The calculus refines the universal capability notion into a new scheme with existential and universal capture set quantification. Intuitively, rcaps witness existentially quantified capture sets inside the boxes of generic types in a way that does not require exposing existential capture types in the surface language. We have fully mechanized the formal metatheory of System Capless in Lean, including proofs of type soundness and scope safety. System Capless supports the same lightweight notation of capturing types plus rcaps, as certified by a type-preserving translation, and also enables fully optional explicit capture-set quantification to increase expressiveness. Finally, we present a full reimplementation of capture checking in Scala 3 based on System Capless and migrate the entire Scala collections library and an asynchronous programming library to evaluate its practicality and ergonomics. Our results demonstrate that reach capabilities enable the adoption of capture checking in production code with minimal changes and minimal-to-zero notational overhead in a vast majority of cases.
Problem

Research questions and friction points this paper is trying to address.

Enabling capability tracking in generic data structures
Overcoming limitations of Scala's capturing types system
Providing lightweight effect polymorphism with minimal overhead
Innovation

Methods, ideas, or system contributions that make the work stand out.

Introduces reach capabilities for naming embedded capabilities
Refines universal capability with existential and universal quantification
Enables capture checking in Scala with minimal overhead
🔎 Similar Papers
No similar papers found.