Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top