A small cabal package for haskell featuring the basic operations of lambda calculus.
- Representation of objects in lambda calculus as data structures
- IO of lambda expressions
- Validity check of lambda expressions
- Stepwise evaluation of lambda expressions
Installation of this library via cabal package manager:
cabal instal --lib
This will register the package for GHC as well.
After a succeccfull installation all modules are known to and importable from within GHC/GHCI.
Lambda.Data
contains all data structures representing the lambda calculus and output functions (show
)Lambda.Parse
contains a parser function for all data structuresLambda.Evaluation
contains functions related to expression evaluation
The standard notation is represented as λx. λy. x y
\x. (\y. (x y))
with explicit parentheses around each function body if more than one term is present and exactly one parameter per function.
Other term lists have to be placed within parentheses as well: becomes (λx. λy. x y) a b
(\x. (\y. (x y)) a b)
.
Use parse
to parse a grammatical data structure like word
(top level structure):
> import Lambda.Parse
> parse word "\\a. \\b. (a b)"
Just (\a. (\b. (a b)))
>
Printing is implicit for each line but one can use show
to turn a grammatical data structure into a string as a in:
> import Lambda.Parse
> w = parse word "\\a. \\b. (a b)"
> show w
"Just (\a. (\b. (a b)))"
>
To check the validity of a lambda expression use valid
as in:
> import Lambda.Parse
> import Lambda.Evaluate
> import Data.Maybe
> w = w = fromJust (parse word "(\\x. \\y. (x y) \\y. (y z))")
> valid w
True
> w = w = fromJust (parse word "(\\x. \\x. (x y) \\y. (y z))")
> valid w
False
>
To perform a single evaluation step (for any valid lambda expression) use eval
as in:
> import Lambda.Evaluate
> import Lambda.Parse
> import Data.Maybe
> w = fromJust $ parse word "(\\x. \\y. (x y) a b)"
> iterate eval w !! 0
((\x. (\y. (x y))) a b)
> iterate eval w !! 1
((\y. (a y)) b)
> iterate eval w !! 2
(a b)
> iterate eval w !! 3
(a b)
>
- haskell compiler: ghc v4.9.0.0 or newer
- archlinux: ghc package (may require further packages)
- haskell package manager: cabal v2.4 or newer