6

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?

4

2 回答 2

5

Haskell 有各种类型的数组,具有不同级别的副作用控制,并且有盒装和非盒装变体。装箱数组是指向值的指针数组,未装箱数组是连续内存块的数组。对于 RAM,您只想将其视为一块连续内存,因此您可能想要使用未装箱的数组类型,如 STUARray 或 IOUArray 或 StorableArray 或类似的。

于 2011-01-17T09:55:23.443 回答
3

我会考虑一个 IO 在底部和一个或多个可变向量来表示 RAM 的 monad 转换器堆栈。

于 2011-01-17T07:34:50.857 回答