🤖 AI Summary
This paper addresses three core challenges in implementing binding structures in Haskell: ensuring scope safety, manually defining substitution and α-equivalence operations, and maintaining invariants under de Bruijn indexing. To resolve these, we introduce *Rebound*, a library centered on **first-class environments**—explicit, typed, first-order values representing variable-to-expression mappings, with scope nesting statically tracked at compile time. This design eliminates the need for manual invariant verification over low-level indices and improves substitution efficiency via environment composition. Rebound supports advanced binding patterns—including those arising in dependently typed languages (e.g., π-forall)—and provides built-in support for hygiene, capture-avoiding substitution, and α-equivalence. Empirical evaluation demonstrates that Rebound outperforms existing approaches in expressiveness, type safety, and runtime performance, while significantly reducing boilerplate and error-proneness in binding-intensive code.
📝 Abstract
We introduce the Rebound library that supports well-scoped term representations in Haskell and automates the definition of substitution, alpha-equivalence, and other operations that work with binding structures. The key idea of our design is the use of first-class environments that map variables to expressions in some new scope. By statically tracking scopes, users of this library gain confidence that they have correctly maintained the subtle invariants that stem from using de Bruijn indices. Behind the scenes, Rebound uses environments to optimize the application of substitutions, while providing explicit access to these data structures when desired. We demonstrate that this library is expressive by using it to implement a wide range of language features with sophisticated uses of binding and several different operations that use this abstract syntax. Our examples include pi-forall, a tutorial implementation of a type checker for a dependently-typed programming language. Finally, we benchmark Rebound to understand its performance characteristics and find that it produces faster code than competing libraries.