Implementing forward refs in monadic assembler and interpreter

Ross Paterson ross@soi.city.ac.uk
Fri, 15 Nov 2002 10:17:40 +0000


On Fri, Nov 15, 2002 at 01:38:03AM -0800, Mike Gunter wrote:
> I need to implement an assembler and interpreter for a simple
> instruction set.
> 
> [...]
> Without forward
> branches, the implementation is reasonably straightforward.  The
> assembler can use a Monad with state and writer capabilities.  The
> interpreter can use a continuation monad to implement branches and a
> state monad for the machine state.
> 
> However, forward branches make things harder.

This is a job for recursive monadic bindings, an extension currently
in Hugs and GHC:

	http://www.cse.ogi.edu/PacSoft/projects/rmb

This can be used if your monads belong to the MonadFix class, and the
monads you need for the assembler do.  The continuation monad doesn't,
however.  See Levent Erkok's papers and thesis on that page for more.