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
("main",L (L (A (A (Free"*") (N (SuccZero))) (NZero))))
109
104
```
110
105
111
-
It's easy to see that the de Bruijn notation is just a different representation of the λ-calculus terms. The only difference is that the variable names are replaced by indices.
112
-
This is quite helpful as it allows to systematically adress variables by their respective position without having to deal with arbitrary variable names.
106
+
It's easy to see that the de Bruijn notation is just a different representation of the λ-term. The only difference is that the variable names are replaced by indices.
107
+
The innermost lambda-abstraction binds the variable `y` which is represented by the index `Zero`. The next lambda-abstraction binds the variable `x` which is represented by the index `Succ Zero`.
108
+
This notation is quite helpful as it allows to systematically adress variables by their respective position in a complex term.
113
109
114
110
But why are we using Peano numbers for the indices? Why not just use integers?
115
111
Well it's definitely possible to [use integers instead of Peano numbers](https://crypto.stanford.edu/~blynn/lambda/cl.html).
@@ -120,11 +116,38 @@ In the subsequent compilation steps we want to be able to do pattern matching on
120
116
dataPeano=SuccPeano | Zero
121
117
```
122
118
123
-
Now we'll take a look at the next step in the compilation process.The function `convert` translates the de Bruijn notation to a datatype `CL` which represents the combinator terms.
119
+
Starting with the de Bruijn notation BenLynn's implementation ofKiselyov's algorithm builds up a series of increasingly optimized compilers that translate λ-expressions to combinator terms.
124
120
121
+
I'll don't want to go into all the details of the algorithm. [Ben's blog post](https://crypto.stanford.edu/~blynn/lambda/kiselyov.html) is a great resource for this.I'll just give a brief overview of the compilation results of the different compilers.
125
122
123
+
## The Plain compiler
124
+
``` haskell
125
+
compilePlain::Environment->CL
126
+
compilePlain env =caselookup"main" env of
127
+
Nothing->error"main function missing"
128
+
Just main ->snd$ plain env (deBruijn main)
129
+
```
130
+
131
+
The first compiler is called `plain`. It is a straightforward translation of the de Bruijn notation to combinators. It uses the `CL` data type to represent combinator-terms:
132
+
133
+
```haskell
134
+
dataCL=ComCombinator | INTInteger | CL:@CL
135
+
136
+
dataCombinator=I | K | S | B | C | Y | R | B' | C' | S' | T |
137
+
ADD | SUB | MUL | DIV | REM | SUB1 | EQL | GEQ | ZEROP
0 commit comments