|
|
|
|
|
by vnorilo
1544 days ago
|
|
Not sure there's any benefit in using the state monad for an interpreter. My first thought is to model a cycle of the interpreter as a function of old state into new state. I guess the state monad could be used to thread the state dataflow through the interpreter, but it would not make the copy-big-buffer any more efficient. Code using the state monad is still pure and uses immutable data. Now if you have to use a mutable buffer (only one fits in memory?) then you could use techniques like the IO monad to deal with it. Disclaimer: Am more Clojure than Haskell person. |
|
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