= Solution
Fix an answer type and let the <continuation> return its answer inside the base <computational monad>:
``
type ContT m a = (a -> m Answer) -> m Answer
result :: Monad m => a -> ContT m a
result x k = k x
bind :: Monad m => ContT m a -> (a -> ContT m b) -> ContT m b
bind p f k = p (\x -> f x k)
``
The <continuation monad transformer> changes the <continuation> supplied to `p`: it first runs `f` on the produced value, then uses the original final <continuation> `k`. Base sequencing is unnecessary in these two definitions because `p` already accepts a <continuation> returning `m Answer`. The customary lift, if desired, is `lift q k = bindM q k`.
$$
\boxed{\begin{aligned}
\operatorname{ContT}\ m\ A&=(A\to m\operatorname{Answer})\to m\operatorname{Answer},\\
\operatorname{result}(x)\,k&=k(x),\\
(p\triangleright f)\,k&=p(\lambda x.\,f(x)\,k).
\end{aligned}}
$$
Back to article page