Solutions to all three questions of the paper dated 11 June 2015.[ref]
Principles of Programming Languages examination paper by the University of Oxford (2015). Cover and pp. 2–8, A12079W1
In the equations below, and denote the base computational monad's result and sequencing operations. All equalities of computations are extensional: apply both sides to the same remaining arguments. Haskell fragments use result and bind for the paper's and . The FunMem programs use the language's own syntax.Reading preserves the computer memory; writing returns the unit type value; allocating returns both the fresh memory location and the allocator's updated computer memory:
get :: Monad m => Location -> MemT m Value
get a s = resultM (contents s a,s)
put :: Monad m => Location -> Value -> MemT m ()
put a v s = resultM ((),update s a v)
new :: Monad m => MemT m Location
new s = resultM (fresh s)These use the memory interface in [ref]
Principles of Programming Languages examination paper by the University of Oxford (2015). Printed p. 3, Figure 1
. In particular, fresh already returns its outputs in the order required by the state monad transformer: