Dealing with Writable Memory in Haskell - Implementation of Infocom's Z-Machine VM
Asked Answered
B

2

5

Many people who were computer enthusiasts in the 80's have heard of the Infocom series of interactive fiction games, notably ones such as 'Zork', 'The Hitchhiker's Guide to the Galaxy', 'Planetfall', 'A Mind Forever Voyaging', etc.

These games were implemented on top of the "Z-Machine" virtual machine. The machine is implemented as a block of RAM, a stack and a virtual processor. The process executes instructions which can dynamically read and write to the RAM.

My question is this: the VMs RAM is dynamic. What is an efficient and reasonably idiomatic way to represent this RAM (and more holistically the structure of the virtual machine) so that I can implement software to run these games? For example, should I use Data.Array to represent the RAM and the state monad?

Benyamin answered 17/1, 2011 at 7:14 Comment(3)
Did you ever implement this?Surname
I'm curious myself, could be very interesting.Cracow
This is now 2022, and I am curious. Has anyone implemented Z-machines in the last 10 years?Bonnybonnyclabber
H
5

Haskell has various types of array with varying levels of side-effect control and in both boxed and unboxed variants. A boxed array is an array of pointers to values, unboxed arrays are arrays of contiguous block of memory. For RAM you just want to treat this as a block of contiguous memory so you probably want to go for an unboxed array type like STUARray or IOUArray or StorableArray or similar.

Hopson answered 17/1, 2011 at 9:55 Comment(0)
P
3

I'd consider a monad transformer stack with IO at the bottom and one or more mutable vectors to represent the RAM.

Psychopathology answered 17/1, 2011 at 7:34 Comment(2)
The unboxed versions in Data.Vector.Unboxed is probably more appropriate.Hopson
If you just want mutable arrays you don’t need all of IO; the ST monad is a purer fit.Dogie

© 2022 - 2024 — McMap. All rights reserved.