[Haskell-cafe] Writing an interpreter for a language with mutability

Jeremy Mikkola jeremy128 at gmail.com
Tue Dec 19 17:37:33 UTC 2017

Hi all, thank you for the replies!

The language this will interpret does not expose pointers (so it acts like
the more modern languages).

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.

Thanks again,

- Jeremy Mikkola

On Mon, Dec 18, 2017 at 12:31 PM, Joachim Durchholz <jo at durchholz.org>

> Am 17.12.2017 um 22:03 schrieb Jeremy Mikkola:
>> How does one go about interpreting a language with mutable objects in
>> Haskell?
>> 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.
> It depends on how data is addressed in the language.
> 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.
> 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).
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20171219/8afa2443/attachment.html>

More information about the Haskell-Cafe mailing list