An implementation of bird forest inspired from To mock a mocking bird.
A lambda calculus and combinatory logic interpreter.
As for now, you can call out the following birds
- I : Idiot
- S : Starling
- K : Kestrel
- B : Bluebird
- C : Cardinal
Most of the birds could be found in the forest, although they are unnamed. Some birds might not terminate, for example, the Y-combinator bird (S(CB(SII))(CB(SII)))
.
The REPL can parse mentioned birds and lambda expression using the de bruijn index notation.
SKK
will be parsed as(SK)K
and returnI
λ[0]
meansλx.x
λλλ[0][1]
meansλxyz.zy
- download haskell and cabal
cabal run birdForest
to open a repl
- run
cabal test
to run the test
All library files are in /src/
, tests are in /test/
and repl is in /app/
- Implemented parsing certain birds listed above
- Parsing detail specified in
Expr.hs
- Parsing algorithm in
Parser.hs
- splited into intepret, (re)sugar
- intepretation break down each bird into the equivalent lambda expression with de bruijn index
- interpretation takes care of reductions and result in a non-reducible lambda expression
- encyclopedia map back the expression to its name
- ie. map
λx.x
orλ0
toI
- ie. map
λxy.x
orλλ1
toK
- ie. map
- prettify by changing de bruijn index notation into named lambda
Expr
is a type that represent the syntax of the language.
Result
is a type of Either String Expr
where the string is the error message
parseExpr :: String -> Result
- parse string into a
Result
- parse string into a
interp :: Expr -> Result
- makes reduction of any Expression containing
S
andK
- makes reduction of any Expression containing
evaluate :: String -> Result
- parse the string, and do
interp
.
- parse the string, and do
encyclopedia :: Expr -> String
- yields the prettiest response with bird name and named lambda expression
prettify :: Expr -> String
- returns the corresponding named lambda expression
show :: Expr -> String
- returns the lambda expression in de bruijn index style