<div dir="auto">Hi Jeremy,<div dir="auto"><br></div><div dir="auto">I'm on my phone right now so I can't link, but try searching for "IORef" and the "ST monad".</div><div dir="auto"><br></div><div dir="auto">Chris</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Dec 18, 2017 10:06, "Jeremy Mikkola" <<a href="mailto:jeremy128@gmail.com">jeremy128@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div>I am quite certain I am not the first to try to do this, but my google-fu is failing me today.<br><br></div>How does one go about interpreting a language with mutable objects in Haskell? <br></div><div><br></div><div><br></div>The
 best approach I can think of is to represent the language's memory as a
 `Data.Map.Map RefID LanguageObject` where RefID is some type (probably 
Int) used as a reference. The LanguageObject structure might contain 
some values of type RefID to refer to other objects. Mutating an object 
involves simply replacing the value in the map at a given RefID.<br></div><div><br></div><div><br></div>I don't like this approach for two reasons:<br><br></div>1. Map lookups aren't very efficient compared with actual references to the value.<br><br></div>2.
 I have to re-invent garbage collection, removing objects from the map 
when they no longer have incoming references. (Unlike simple 
interpreters for languages with immutable values, I can't rely on 
Haskell's garbage collector to do the work for me.)</div><div><br></div><div><br></div><div>Is there a better approach?</div><div><br></div><div><br></div><div>- Jeremy<br></div></div>
<br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div></div>