blanks

Fill-in-the-blanks - A library factoring out substitution from ASTs

https://github.com/ejconlon/blanks#readme

LTS Haskell 22.39:0.5.0
Stackage Nightly 2023-12-29:0.5.0
Latest on Hackage:0.5.0

See all snapshots blanks appears in

BSD-3-Clause licensed by Eric Conlon
Maintained by [email protected]
This version can be pinned in stack with:blanks-0.5.0@sha256:8fffd5088cdbadecb5c547408456d9d41ca288fd59a8e66af5e610251cac9ec0,3063

blanks

CircleCI

Fill-in-the-blanks - A library factoring out substitution from ASTs.

It’s a pain to track de Bruijn indices yourself to implement capture-avoiding subsititution, so this library provides some wrappers that help. One of the best libraries for this is bound, which uses a clever representation to make these operations safe and fast. The tradeoff is that you have to define a Monad instance for your expression functor, which in practice can be tricky. (It’s even trickier to derive Eq and Show!)

This library takes the simpler, slower, and rather “succ-y” free-monad-ish approach, but with a twist. It expects you to rewrite all name-binding constructors in your expression as annotations on a single “binder” constructor. This allows you to use the provided Scope type (or a variant) as a wrapper around your expression functor, which is only required to implement Functor. This representation is less safe (since you can inspect and manipulate bound variables), but if you stick to the provided combinators, things will work out fine.

You’ll get most of what you want by just importing this module unqualified. See Scope for the basic wrapper and LocScope for a wrapper with annotations you can use for source locations and the like. See the test suite for examples.