🤖 AI Summary
This work addresses the challenge of safely supporting Rust-like non-local borrowing for flexible parallel state mutation while preserving the purity, laziness, and polymorphism inherent to purely functional languages. We propose Pure Borrow, a novel framework that, for the first time in Linear Haskell, realizes Rust-style borrowing without requiring explicit ownership return. By introducing a history-based borrowing model, Pure Borrow leverages affine mutable references to enable safe parallel state mutation, guaranteeing memory safety, leak freedom, and confluence. Implemented as a library, Pure Borrow is successfully applied to parallel computing scenarios and backed by a formal core calculus that provides rigorous theoretical assurance of its correctness.
📝 Abstract
A promising approach to unifying functional and imperative programming paradigms is to localize mutation using linear or affine types. Haskell, a purely functional language, was recently extended with linear types by Bernardy et al., named Linear Haskell. However, it remained unknown whether such a pure language could safely support non-local \emph{borrowing} in the style of Rust, where each borrower can be freely split and dropped without direct communication of ownership back to the lender.
We answer this question affirmatively by \emph{Pure Borrow}, a novel framework that realizes Rust-style borrowing in Linear Haskell with purity. Notably, it features parallel state mutation with affine mutable references inside pure computation, unlike the IO and ST monads and existing Linear Haskell APIs. It also enjoys purity, lazy evaluation, first-class polymorphism and leak freedom, unlike Rust. We implement Pure Borrow simply as a library in Linear Haskell and demonstrate its power with a case study in parallel computing. We formalize the core of Pure Borrow and build a metatheory that works toward establishing safety, leak freedom and confluence, with a new, history-based model of borrowing.