|
|
|
|
|
by ChadNauseam
1544 days ago
|
|
Writing efficient interpreters in a functional style is not easy. I write interpreters in OCaml for a living and we had to switch to a mutation-heavy style for performance and memory usage reasons. It can be done though. When you think about it, any dependently typed language has to have an interpreter inside it, because you can put function applications inside a type and the typechecker will probably need to evaluate the application at some point. The go-to technique is to use Normalization by Evaluation [0], where you convert the AST version of a function in the interpreted language to an actual function in the host language, and piggyback off the host language's (presumably very fast) function application. [0]: https://en.wikipedia.org/wiki/Normalisation_by_evaluation |
|
(Of course you can only access the actual local state and not do I/O or anything like that.)