You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-4
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,16 @@
1
1
# lambda-parser
2
-
Parser for lambda terms, written in Haskell, that is also able to apply substitution, according to the rules of lambda calculus
2
+
Parser for lambda terms, written in Haskell, that is also able to execute a list of operations on the terms
3
3
4
4
## Table of contents
5
5
-[Prerequisites](#prerequisites)
6
6
-[Running the project](#running-the-project)
7
7
-[Installing the executable manually](#installing-the-executable-manually)
8
8
-[Documentation](#documentation)
9
9
-[Grammar](#grammar)
10
-
-[Substitution](#substitution)
10
+
-[Supported operations](#supported-operations)
11
+
-[Substitution](#substitution)
12
+
-[Transformation to applicative term](#transformation-to-applicative-term)
13
+
-[Counting beta-redexes](#counting-beta-redexes)
11
14
-[License](#license)
12
15
-[Contacts](#contacts)
13
16
@@ -35,7 +38,7 @@ cabal install
35
38
Now the executable should be located in the configured `installdir` of `cabal` (usually `~/.local/bin` or `~/.cabal/bin`).
36
39
37
40
## Documentation
38
-
The parser traverses the lambda term and creates AST where the nodes are variables, applications and abstractions (lexing and parsing are done simultaneously). Then the substitution is done on the AST with the corresponding tokens instead of directly on the term. After the substitution, a new lambda term is generated based on the newly created AST and the result is returned as the final answer. If there are no brackets, the application term is left associative. Bear in mind that in the generated final term some brackets may be added because there is no way to know where they can be skipped without looking ahead, which the current generator does not do.
41
+
The parser traverses the lambda term and creates AST where the nodes are variables, applications and abstractions (lexing and parsing are done simultaneously). Then the operations are done on the AST with the corresponding tokens instead of directly on the term. After the operation, a new lambda term is generated based on the newly created AST and the result is returned as the final answer. If there are no brackets, the application term is left associative. Bear in mind that in the generated final term some brackets may be added because there is no way to know where they can be skipped without looking ahead, which the current generator does not do.
(Here $` (\!( \ )\!)^* `$ means that the brackets themselves are optional)
47
50
48
-
### Substitution
51
+
### Supported operations
52
+
This is the list of currently supported operations, that can be executed on the terms after parsing:
53
+
54
+
#### Substitution
49
55
There are currently 2 supported versions for the substitutions:
50
56
- curry substitution - this is the standart substitution, done directly on the original term. In order for it to be correct and not change the semantics of the lambda terms, in the cases where a naive substitution would cause a problem, the bound variables are renamed. The algorithm starts by trying all letters, starting from *a*, until a letter is found that would not cause the term to change its semantics and renames the bound variable with the found letter. If a suitable letter is not found, then the algorithm continues to search for any suitable character (which does not follow the grammar);
51
57
- nameless term substitution - in order for this substitution to be applied the term is first transformed into nameless term. Nameless terms don't have variable names - instead de Bruijn indexes are used to denote which variables are bound and which - free. The substitution is then done on the indexes instead of the variables by utilizing the `shift` function. After the substitution is done, the term is transformed back into its named version, where the bound variables may have different names (which does not change the semantics of the term).
52
58
59
+
#### Transformation to applicative term
60
+
The transformation to applicative term is non-deterministic operation because there are 2 approaches to it - either to start from the outside or the inside. The algorithm always starts from the outside, except in the case where starting from the outside would not lead to the full transformation - this is the case where there are 2 nested abstractions where the argument of the first is part of the free variables of the second. When this case is encountered the transformation is applied to the inner abstraction first and after it is done the partial result is transformed again to achieve the coorect result.
61
+
62
+
#### Counting beta-redexes
63
+
Counting the beta-redexes in s single term is the simplest operation. The algorithm traverses the AST and counts the occurences of applications where the first argument is abstraction.
64
+
53
65
## License
54
66
The project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more information.
0 commit comments