Skip to content

BillyBadBoy/lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Y = λf.(λx.f(x x)) (λx.f(x x))

This repo contains my experiments with untyped lambda calculus implemented in Haskell. I got the idea from the Futurelearn Haskell mooc, which I did a while back. It's all implemented from first principles using only stuff available from the Haskell prelude.

There are some notes on the implementation here

Installation

  1. install stack - the haskell build tool
  2. ensure stack is up-to-date:
$ stack upgrade
  1. clone this repo:
$ git clone https://github.com/BillyBadBoy/lambda.git
  1. cd into the newly created directory:
$ cd lambda
  1. compile the executable (lam-exe):
$ stack install

Running the repl

Once the installation is complete you can run a repl session.

Start the repl:

~/haskell/lambda $ lam-exe
Enter cmd:

Load some basic definitions:

Enter cmd:
loadDefs ./scripts/core.txt
> Defintions added to environment.
Enter cmd:
eval True
> Expression evaluates to:
λx yx

Evaluate Not True:

Enter cmd:
evalBoolAll Not True
> Expression evaluates to:
step 0:
(λx(λp x yp x y) x (λx yy) (λx yx)) (λx yx)
step 1:
(λp x yp x y) (λx yx) (λx yy) (λx yx)
step 2:
(λx y(λx yx) x y) (λx yy) (λx yx)
step 3:
(λy(λx yx) (λx yy) y) (λx yx)
step 4:
(λx yx) (λx yy) (λx yx)
step 5:
(λy x yy) (λx yx)
step 6:
λx yy
which is recognized as: False
> end.

Evaluate 1 + 1:

Enter cmd:
evalIntAll Plus One One
> Expression evaluates to:
step 0:
(λm n f(λf g xf (g x)) (m f) (n f)) (λf xf x) (λf xf x)
step 1:
(λn f(λf g xf (g x)) ((λf xf x) f) (n f)) (λf xf x)
step 2:
λf(λf g xf (g x)) ((λf xf x) f) ((λf xf x) f)
step 3:
λf(λg x(λf xf x) f (g x)) ((λf xf x) f)
step 4:
λf x(λf xf x) f ((λf xf x) f x)
step 5:
λf x(λxf x) ((λf xf x) f x)
step 6:
λf xf ((λf xf x) f x)
step 7:
λf xf ((λxf x) x)
step 8:
λf xf (f x)
which is recognized as: 2
> end.
Enter cmd:
quit

More information about using the repl can be found here

About

Experiments with lambda calculus using Haskell

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published