<div dir="ltr"><div><div>"Write Yourself a Scheme in 48 Hours"[1] is a tutorial about implementing Scheme in Haskell. It takes the approach of modeling mutable variables in Scheme using IORefs. It's a good place to start learning about these ideas—in fact, it's pretty much how I learned Haskell.<br><br></div>Looking back at it now I'm not sure I would make the same decisions as the author any more, but it worked and the tutorial does a good job of guiding you through what the code does. 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.<br><br>[1]: <a href="https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours">https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours</a><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 19, 2017 at 9:37 AM, Jeremy Mikkola <span dir="ltr"><<a href="mailto:jeremy128@gmail.com" target="_blank">jeremy128@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi all, thank you for the replies!<br><br></div>The language this will interpret does not expose pointers (so it acts like the more modern languages).<br><br></div>I have started to try to wrap my head around IORef and that monad (anyone know of a "for dummies" guide to those?). I think that they will likely be exactly what I need.<br><br></div>Thanks again,<br></div><div class="gmail_extra"><br clear="all"><div><div class="m_-5701527595984855829gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div>- Jeremy Mikkola</div></div></div></div></div><div><div class="h5">
<br><div class="gmail_quote">On Mon, Dec 18, 2017 at 12:31 PM, Joachim Durchholz <span dir="ltr"><<a href="mailto:jo@durchholz.org" target="_blank">jo@durchholz.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>Am 17.12.2017 um 22:03 schrieb Jeremy Mikkola:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
How does one go about interpreting a language with mutable objects in Haskell?<br>
<br>
<br>
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.<br>
</blockquote>
<br></span>
It depends on how data is addressed in the language.<br>
If you wanto interpret a C-style language where every address can be cast to an int, then that's the most straightforward (though not necessarily best) approach.<br>
If it is just references to objects as in most, erm, "more modern" languages, the Id can be any type. E.g. something based on the language's data model - Int | Real | Record | Array, with type parameters as appropriate. Upside is that you leverage the Haskell GC that way, downside is that you'll need a recursive type (Array is really Array RefId, and my Haskell-fu is hilariously inadequate to properly flesh out that recursion).<div class="m_-5701527595984855829HOEnZb"><div class="m_-5701527595984855829h5"><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-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.</div></div></blockquote></div><br></div></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><br></div>