Solution (source code)

= Solution

Apply the memory interface before invoking the supplied <continuation>:

``
get :: Location -> M Value
get a k s = k (contents s a) s

put :: Location -> Value -> M ()
put a v k s = k () (update s a v)

new :: M Location
new k s = let (a,s') = fresh s in k a s'
``

A read preserves <computer memory>; a write changes it but returns the <unit type> value; an allocation uses the updated <computer memory> returned by `fresh`. The <continuation> always receives the latest <computer memory>:
$$
\boxed{\begin{aligned}
\operatorname{get}(a)\,k\,s&=k(\operatorname{contents}(s,a))\,s,\\
\operatorname{put}(a,v)\,k\,s&=k(())(\operatorname{update}(s,a,v)),\\
\operatorname{new}\,k\,s&=k(a)\,s'\quad\text{where }(a,s')=\operatorname{fresh}(s).
\end{aligned}}
$$