2024-01-08 23:44:03 +03:00
# Compilation and readback
How are terms compiled to interaction net nodes?
2024-05-06 22:14:23 +03:00
HVM has a bunch of useful nodes to write IC programs.
2024-01-08 23:44:03 +03:00
Every node contains one `main` port `0` and two `auxiliary` ports, `1` and `2` .
2024-05-06 22:14:23 +03:00
There are 7 kinds of nodes, Eraser, Constructor, Duplicator, Reference, Number, Operation and Match.
2024-01-08 23:44:03 +03:00
A lambda `λx x` compiles into a Constructor node.
An application `((λx x) (λx x))` also compiles into a Constructor node.
```
0 - Points to the lambda occurrence 0 - Points to the function
| |
λ Lambda @ Application
/ \ / \
1 2 - Points to the lambda body 1 2 - Points to the application occurrence
| |
Points to the lambda variable Points to the argument
```
When reading back, if we visit a Constructor via port 0 then we know it's a lambda, and if we visit it via port 2 it's an application.
- The `Number` node uses the label to store it's number.
2024-05-06 22:14:23 +03:00
- An `Operation` node uses the label to store it's operation.
2024-01-08 23:44:03 +03:00
2024-05-06 22:14:23 +03:00
A duplication `let {a b} = x` compiles into a Duplicator node.
A superposition `{a b}` compiles to a Duplicator node too. The difference here comes from context too.
2024-01-08 23:44:03 +03:00
```
2024-02-26 17:32:33 +03:00
0 - Points to the sup occurrence 0 - Points to the duplicated value
2024-01-08 23:44:03 +03:00
| |
# Superposition # Duplication
/ \ / \
1 2 - Points to the second value 1 2 - Points to the second binding
| |
Points to the first value Points to the first binding
```
Check out [HVM-Core ](https://github.com/HigherOrderCO/hvm-core/tree/main#language ), one of the Higher Order Company's projects, to know more about this.