The Writing an interpreter with OCaml GADTs finishes with
It is possible to have a typed interpreter that avoids the type reconstruction (and the string comparison!) by enforcing the correspondence between variable indices and environments at the type level, but that gets complicated.
Does anyone have an example?
I’m rewriting my compiler from Zig to OCaml and need to implement value environments to know the expression that variables hold at any given moment. I use this for inlining.