From fdf35536b66499884dd5b4e1740ac67e5cebb1a2 Mon Sep 17 00:00:00 2001 From: tzlil Date: Fri, 14 Apr 2023 23:46:53 +0300 Subject: add homework material --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..9195860 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Lambda Calculus Expressions + +## Building + +Use the Haskell Tool Stack [https://www.haskellstack.org] + +`stack build` + +## Testing + +``` +cd tests +./runtests.sh +beta1...OK +beta2...OK +beta3...OK +``` + +## Use + +``` +stack ghci +ghci> parse "x y z" +x y z +ghci> parse "(\\ n . pred n) 3" +(\n . pred n) 3 +ghci> parse "x (y z)" +x (y z) +ghci> parse "(x y) z" +x y z +ghci> parse "\\x.y z" +\x . y z +ghci> parse "\\x y z . x (y z)" +\x . \y . \z . x (y z) +ghci> parse "\\x.x (\\z . z)" +\x . x (\z . z) +ghci> parse "(\\x.x) (\\z . z)" +(\x . x) (\z . z) +ghci> :i Expr +type Expr :: * +data Expr = Var String | Lam String Expr | App Expr Expr +instance Show Expr +ghci> Lam "a" (App (Var "b") (Var "c")) +\a . b c +``` + +# Syntax + +``` + ::= -- variable + | `\' + `.' -- lambda abstraction + | -- application + | `(' `)' -- grouping +``` + +Variable identifiers are any sequence of characters excluding +`\`, `.`, `(`, `)`, `-`, and whitespace + +Lambda abstractions are at the lowest precedence; +application binds left-to-right + +Space is needed to separate identifiers but is optional elsewhere + +Single-line comments start with `--` + +Multi-line comments are between `{-` and `-}' and may nest -- cgit 1.4.1