A functional language for reasoning about formal systems, with higher-order abstract syntax and contexts as first-class objects.

close.bel
LF tm : type =
  | lam : (tm  tm)  tm
  | app : tm  tm  tm;

schema ctx = tm;

% bind each free variable under a λ
rec close : {g:ctx} [g  tm]  [  tm] =
  mlam g  fn t  case t of
  | [  _]          t
  | [g', x:tm  T] 
      close [g'] [g'  lam \u. T];

Beluga allows specification of formal systems (such as lambda calculi and type systems) using a foundation of contextual modal logic. As in the Twelf system, we can encode object-level binding constructs using higher-order abstract syntax. We also pair terms with the contexts that give them meaning and then reason about these contextual objects. Proofs in Beluga are represented by recursive programs according to the Curry–Howard isomorphism.

Install

Beluga ships as an opam package for Linux, WSL (Windows Subsystem for Linux), and macOS.

Quickstart

Install opam, then initialize it:

opam init
eval $(opam env)

Install Beluga and refresh your shell environment:

opam install beluga
eval $(opam env)

You should now have beluga and harpoon in $OPAM_SWITCH_PREFIX/bin.

Check a file or start Harpoon:

beluga path/to/program.bel
harpoon --sig path/to/program.bel

Click below if you run into any issues.

Full install guide

Prerequisites

The published package needs OCaml ≥ 4.14; opam pulls the rest. Optional: rlwrap for nicer interactive sessions. Building from source also needs GNU Make 4.0+.

After opam init, accept shell-hook setup if offered so new terminals pick up opam automatically. Otherwise run eval $(opam env) in every shell before calling beluga or harpoon.

Installing opam

Debian / Ubuntu (and Ubuntu under WSL):

sudo apt-get update
sudo apt-get install opam
# optional
sudo apt-get install rlwrap

macOS (via Homebrew):

brew install opam
# optional
brew install rlwrap

WSL: install WSL, open your Linux distribution, then follow the Debian/Ubuntu steps.

Dedicated opam switch

If opam install beluga hits dependency conflicts in a shared switch, use an empty local switch:

mkdir beluga-switch && cd beluga-switch
opam switch create . --empty
opam install beluga
eval $(opam env)

Uninstall with opam remove beluga.

Install from source

For the development tip instead of the last opam release. Requires Git and GNU Make:

git clone https://github.com/Beluga-lang/Beluga.git Beluga
cd Beluga
make setup-install
make install
eval $(opam env --switch=. --set-switch)

Uninstall with make uninstall from the clone.

Contributors who want tests and docs tooling should use make setup-development instead — see the repository README (make, make test, dune exec …).

Emacs mode

Major mode in the repo’s tools/ directory. Add to ~/.emacs or ~/.emacs.d/init.el (replace path/to/beluga):

(add-to-list 'load-path "path/to/beluga/tools/")
(load "beluga-mode.el")

Restart Emacs. Ensure beluga / harpoon are on the PATH Emacs sees (same eval $(opam env) environment as your shell).

Troubleshooting

Command not found after install — run eval $(opam env) again (or eval $(opam env --switch=. --set-switch) inside a source clone).

Inconsistent interface assumptions after a partial build:

make clean
make install

Failed install on windows? Use WSL instead. Currently Beluga depends upon linenoise, which has POSIX headers, and so opam install beluga will not complete.

Case studies

Beginner

Close Terms

We build a simple program that closes open terms, converting each free variable to one bound by a lambda abstraction. The example demonstrates pattern matching on contexts and Beluga's built-in mechanism for variable substitution.

Beginner

Type Uniqueness

Since Beluga does not support equality types, we implement equality using an LF type family as a dependent kind. The difficulties of defining equality via reflexivity in Twelf do not arise in Beluga. Beluga's proof is implemented as a function using pattern matching instead of relations; as we pattern match we learn more about the given derivations and information flows as expected.

Intermediate

Parallel Reduction

The order of assumptions in a context is important in Beluga. However, sometimes the need to reorder assumptions arises, as is illustrated in the proof of the substitution lemma for algorithmic equality. As in Twelf this kind of proof does not come for free in Beluga.

Intermediate

Polymorphic Algorithmic Equality

In order to prove algorithmic equality for a polymorphic lambda-calculus, we establish schemas with alternating assumptions, depending on the type of the variable.

Intermediate

Poplmark

This example shows a solution of the POPLMARK Challenge Part 1A, Transitivity of Subtyping.

Intermediate

Untyped Algorithmic Equality — Context Relation

Context relationships can be defined explicitly using inductive datatypes. In this proof we use inductive datatypes to establish strengthening and weakening between contexts.

Intermediate

Untyped Algorithmic Equality — Context Subsumption

This example demonstrates Beluga's capacity for automatic context subsumption. If schema W is a prefix of a schema W0, then we can always use a context of schema W0 in place of a context of schema W.

Advanced

Normalization by Evaluation

A normalization by evaluation algorithm for an intrinsically typed simply-typed lambda calculus.

Advanced

Weak Normalization

A proof of weak head normalization for the simply typed lambda calculus using logical relations.

People

McGill's Computation and Logic (Complogic) Group is the team behind Beluga, focused on developing a theoretical and practical foundation for building and reasoning about software systems. Research areas include logic and programming languages, type theory, logical frameworks and software verification.

Faculty

McGill University

Collaborators

Chalmers and Gothenburg University
University of Ottawa
INRIA Futurs/École Polytechnique
University of Milan
Université de Montréal
IMDEA-Software
Carnegie Mellon University
IT University of Copenhagen

Visitors

(Ecole Normale Superieur Paris)
(IT University of Copenhagen)

Graduate Students

Jacob Errington
MSc
Aliya Hameer
MSc
Stefan Knudsen
MSc

Past McGill Students

PhD ABS, now at Nuance
PhD, now at Imperial College
Shawn Otis
MSc
MSc, now at Princeton
Rohan Jacob-Rao
MSc, now at Digital Asset
BSc, now at Stanford

Past Postdocs