Destination Calculus: A Linear λ-Calculus for Purely Functional Memory Writes
Thomas Bagrel, Arnaud Spiwack
TL;DR
Destination Calculus develops bb, a pure functional λ-calculus with destinations that enables writing into holes within data structures while preserving immutability and safety. The key innovation is a modal, linear type system with an age semiring that tracks both linear usage and scope, allowing destinations to be first-class values stored inside structures with holes. The work provides concrete encodings of classic DPS concepts, develops data structures like lists and queues using holes and difference lists, and demonstrates a breadth of programs (e.g., breadth-first traversal) that are expressible in this framework. A formal type-safety proof in Coq underpins the language design, and an implementation strategy based on in-place mutations is outlined, connecting theory to practical memory-management ideas. Overall, bb offers a unified, verifiable foundation for reasoning about destination-passing in pure functional settings and informs future typed intermediate representations and DPS-inspired optimizations.
Abstract
Destination passing -- aka. out parameters -- is taking a parameter to fill rather than returning a result from a function. Due to its apparently imperative nature, destination passing has struggled to find its way to pure functional programming. In this paper, we present a pure functional calculus with destinations at its core. Our calculus subsumes all the similar systems, and can be used to reason about their correctness or extension. In addition, our calculus can express programs that were previously not known to be expressible in a pure language. This is guaranteed by a modal type system where modes are used to manage both linearity and scopes. Type safety of our core calculus was proved formally with the Coq proof assistant.
