A Lambda-Calculus Playground in Rust and WebAssembly

A Lambda-Calculus Playground in Rust and WebAssembly

As a fun project, I’ve been working on a lambda-calculus interpreter written in Rust. The same interpreter supports a command-line application and the interactive playground below, compiled to WebAssembly.

What it evaluates

The language has three forms:

  • Variables, such as x.
  • Abstractions, such as λx. x.
  • Applications, such as (λx. x) y.

An abstraction binds a variable in its body. Applying it to an argument performs beta reduction: substitute the argument for that bound variable, without capturing free variables.

For example:

(λx. x) y
→ y

The interpreter accepts either λ or a backslash for abstraction. Application associates to the left, so f x y means (f x) y.

Try it

Enter (λx. x) y and choose Parse, Step, or Run. The examples menu provides more expressions to explore.

  • Parse checks the expression and reports its size and free variables.
  • Step performs one reduction using the selected evaluation strategy.
  • Run evaluates from the input expression within the specified budgets.
  • Reset clears the displayed trace.
  • Cancel terminates the evaluation worker.

The strategies are normal order, call by name, and call by value. Try the same expression under different strategies and compare the reduction traces.

Not every expression terminates. The step budget limits the number of reductions; the size budget limits the size of intermediate terms. Reaching either limit means evaluation stopped, not that the expression has reached a normal form.

Publishing it here

The Rust build produces JavaScript and a WebAssembly binary. Those files are published as static assets alongside this Org-generated article.

There is no server-side evaluation: expressions are evaluated locally in the browser.