= Solution
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 <Principles of Programming Languages examination paper by the University of Oxford (2015)>[Printed p. 3, Figure 1]{ref}. In particular, `fresh` already returns its outputs in the order required by the <state monad transformer>:
$$
\boxed{\begin{aligned}
\operatorname{get}(a)\,s&=r_m(\operatorname{contents}(s,a),s),\\
\operatorname{put}(a,v)\,s&=r_m((),\operatorname{update}(s,a,v)),\\
\operatorname{new}\,s&=r_m(\operatorname{fresh}(s)).
\end{aligned}}
$$
Back to article page