[Haskell-cafe] Writing an interpreter for a language with mutability
Will Yager
will.yager at gmail.com
Tue Dec 19 20:52:01 UTC 2017
> After you follow that, you should have a good feeling for how IORefs work in Haskell and how they fit into an interpreter for a mutable language.
I’m not sure why people jumped to IORefs so quickly. Since you need to look up variable names to get to the IORef underlying the variable anyway, it seems like you might as well avoid IO and just use a (hash)map from variable names to values.
If you really need the speed boost, you will probably want to instrument different mutable implementations anyway, so you will probably want an interpreter that’s generic over the choice of mutable variable representation.
I would make a monad typeclass that encapsulates whatever operations you need on variables, and test it with “StateT (HashMap VarName VarVal)” (pure baseline), something with IORefs, something with ST (preferable to IO), etc.
—Will
More information about the Haskell-Cafe
mailing list