about summary refs log tree commit diff
path: root/README.md
blob: 9195860f5d34cd3b9bd5440c00c637f4fa1d7667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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

```
<expr>  ::= <id>                  -- variable
          | `\' <id>+ `.' <expr>  -- lambda abstraction
          | <expr> <expr>         -- application
          | `(' <expr> `)'        -- 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