rebound: A variable binding library based on well-scoped de Bruijn indices.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

Please see the README on GitHub at https://github.com/sweirich/rebound


[Skip to Readme]

Properties

Versions 0.1.0.0
Change log ChangeLog.md
Dependencies base (>=4.15 && <5.0), containers, deepseq, fin (>=0.3), HUnit, mtl, prettyprinter, QuickCheck, rebound, vec [details]
License MIT
Copyright 2025 Stephanie Weirich, Noe De Santo
Author Stephanie Weirich, Noe De Santo
Maintainer sweirich@seas.upenn.edu, ndesanto@seas.upenn.edu
Category Language
Home page https://github.com/sweirich/rebound
Bug tracker https://github.com/sweirich/rebound/issues
Uploaded by sweirich at 2025-09-10T20:46:38Z

library rebound

Modules

  • Data
    • Data.Fin
    • Data.LocalName
    • Data.SNat
    • Scoped
      • Data.Scoped.Classes
      • Data.Scoped.List
      • Data.Scoped.Maybe
      • Data.Scoped.Telescope
    • Data.Vec
  • Rebound
    • Bind
      • Rebound.Bind.Local
      • Rebound.Bind.Pat
      • Rebound.Bind.PatN
      • Rebound.Bind.Scoped
      • Rebound.Bind.Single
    • Rebound.Classes
    • Rebound.Context
    • Rebound.Env
      • Rebound.Env.Functional
      • Rebound.Env.Lazy
      • Rebound.Env.LazyA
      • Rebound.Env.LazyB
      • Rebound.Env.Strict
      • Rebound.Env.StrictA
      • Rebound.Env.StrictB
    • Rebound.Generics
    • Rebound.Lib
    • Rebound.MonadNamed
    • Rebound.MonadScoped
    • Rebound.Refinement

library rebound:rebound-examples

Modules

  • DepMatch
  • HOAS
  • LC
  • LCLet
  • LCQC
  • LinLC
  • PTS
  • Pat
  • PureSystemF
  • ScopeCheck
  • SystemF

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for rebound-0.1.0.0

[back to package description]

Rebound

Rebound is a variable binding library based on well-scoped de Bruijn indices and environments.

This library is represents variables using the index type Fin n; a type of bounded natural numbers. The key way to manipulate these indices is using an environment, a simultaneous substitutions similar to a function of type Fin n -> Exp m. Applying an environment converts an expression in scope n to one in scope m.

Design goals

The goal of this library is to be an effective tool for language experimentation. Say you want to implement a new language idea that you have read about in a PACMPL paper? This library will help you put together a prototype implementation quickly.

  1. Correctness: This library uses Dependent Haskell to statically track the scopes of bound variables. Because variables are represented by de Bruijn indices, scopes are represented by natural numbers, bounding the indices that can be used. If the scope is 0, then the term must be closed.

  2. Convenience: The library is based on a type-directed approach to binding, where AST terms can indicate binding structure through the use of types defined in this library. As a result the library provides a clean, uniform, and automatic interface to common operations such as substitution, alpha-equality, and scope change.

  3. Efficiency: Behind the scenes, the library uses explicit substitutions (environments) to delay the execution of operations such as shifting and substitution. However, these environments are accessible to library users who would like fine control over when these operations.

  4. Accessibility: This library comes with several examples demonstrating how to use it effectively. Many of these are also examples of programming with Dependent Haskell.

Examples

Calculi

  1. Untyped lambda calculus

    Defines the syntax and substitution functions for the untyped lambda calculus. Uses these definitions to implement several interpreters.

  2. Untyped lambda calculus with let rec and nested lets

    Example of advanced binding forms: recursive definitions and sequenced definitions.

  3. Untyped lambda calculus with pattern matching

    Extends the lambda calculus example with pattern matching.

  4. System F

    Working with two separate scopes (type and term variables) is tricky. This example shows one way to do it.

  5. Pure System F

    An alternative way of defining System F, using one single syntactic class. Also demonstrates how to use the ScopedReader monad for typechecking and pretty-printing.

  6. Simple implementation of dependent types

    An implementation of a simple type checker for a dependent-type system. Language includes Pi and Sigma types.

  7. Dependent Pattern Matching

    A dependent type system with nested, dependent pattern matching. Patterns may also include scoped terms.

  8. Linear Lambda Calculus

    A linear version of the (simply typed) lambda calculus. Demonstrates how to thread a typing context using the ScopedState monad.

Working with well-scoped expressions

  1. Scope checking

    Demonstrates how to convert a "named" (or nominal) expression to a well-scoped expression.

  2. QuickCheck

    Demonstrates the use of well-scoped terms with QuickCheck.

  3. HOAS

    Demonstrates how to layer a HOAS representation on top of a de Bruijn representation. Based on Conor McBride's "Classy Hack".

  4. PatGen

    A variant of the Pat example, which demonstrates how generic programming can be used to derive some definitions.