An interpreter and compiler for simply typed lambda calculus!
Find a file
2023-06-15 18:00:02 +02:00
.github/workflows redacted prelude solutions 2023-04-17 08:55:09 +02:00
.vscode redacted prelude solutions 2023-04-17 08:55:09 +02:00
src Restructured 2023-06-15 18:00:02 +02:00
.envrc redacted prelude solutions 2023-04-17 08:55:09 +02:00
.gitattributes redacted prelude solutions 2023-04-17 08:55:09 +02:00
.gitignore redacted prelude solutions 2023-04-17 08:55:09 +02:00
flake.lock redacted prelude solutions 2023-04-17 08:55:09 +02:00
flake.nix Restructured 2023-06-15 18:00:02 +02:00
fourmolu.yaml redacted prelude solutions 2023-04-17 08:55:09 +02:00
hie.yaml redacted prelude solutions 2023-04-17 08:55:09 +02:00
LICENSE redacted prelude solutions 2023-04-17 08:55:09 +02:00
README.md Update README.md 2023-04-17 09:08:58 +02:00
shell.nix redacted prelude solutions 2023-04-17 08:55:09 +02:00
test.lmd Restructured 2023-06-15 18:00:02 +02:00
typed-lambda.cabal Restructured 2023-06-15 18:00:02 +02:00

lambda

This is a small lambda calculus interpreter, it contains no built-in functions, datatypes etc. so you have to define everything yourself! The only small QoL feature is that natural numbers (1, 2, ...) get parsed to their respective church encoding (\f.\a.f a, \f.\a.f (f a)), ...) and the interpreter tries to parse results as some standard church encodings.

Usage

For best results you should run it using Nix, but using plain cabal should work in most cases as well!

To run the interpreter just do

cabal run lambda

Syntax

A lambda calculus term can be one of:

  • a variable
  • application of two terms
  • lambda abstracion

This interpreter can handle lambda-terms and also supports declarations (assigning a name to a lambda-term). Following example should showcase all features:

> i = \x.x
> s = \x.\y.\z.x z (y z)
> k = \x.\y.x
> s k k x
s k k x
(\x.\y.\z.x z (y z)) k k x
(\v$0.\v$1.k v$1 (v$0 v$1)) k x
(\v$0.k v$0 (k v$0)) x
k x (k x)
(\x.\y.x) x (k x)
(\v$0.x) (k x)
x

Behind the scenes the interpreter just exhaustively applies beta- and eta-reductions.

Prelude

You can supply a prelude (a collection of functions that are loaded when the interpreter is started) to the interpreter in a file prelude.lmd.