On this paper, the author suggests a translation between lambda terms:
data Term = Zero | Succ Term | App Term Term | Lam Term
and interaction nets:
data Net = -- if I understood correctly
Apply Net Net Net
| Abstract Net Net Net
| Delete Net Net Int
| Duplicate Net Net Net Int
| Erase Net
Unfortunately I can not understand his compilation algorithm. It seems like the actual algorithm is missing, and I have no idea what he means with the images on the third page. I've tried understanding it by looking at the published source code, but the author defines it using his own graph rewriting DSL so I would have to learn it first. How exactly is the translation implemented as a normal Haskell function?
I have an implementation of interaction net reduction in Haskell that uses
STRef
s to represent the net graph structure in a mutable way:Conversion from lambda terms is implemented in a separate module. It is not the nicest code I've ever written, because it's a straight transliteration of a Javascript implementation and I didn't really take the time to understand what the JS version is doing:
It also implements the reverse transformation: