Ever used CPS style? Instead of producing values and passing them back to callers you provide continuations to functions and then they never return, merely calling the continuation instead. It turns out that this can save a lot of stack space and it also turns out that you can convert any program into this style should you choose.<p>It might not be exactly clear why CPS is equivalent to &quot;direct&quot; style. The answer is the Yoneda Lemma.<p>Yoneda goes further. Normally you could maybe notate a CPS style function as follows<p><pre><code>    (a -&gt; *) -&gt; *
</code></pre>
where `a` is the type of the value the computation will pass to the continuation function (the first argument here) and * is a special type indicating &quot;will never return&quot;. We can generalize this slightly as<p><pre><code>    forall x . (a -&gt; x) -&gt; x
</code></pre>
which enables us to talk about CPS&#x27;d code in a slightly more general way by not stating exactly what the continuation does—it produces some kind of value, which might be the &quot;will never return&quot; value, and the CPS&#x27;d function just needs to evaluate it because the forall is positioned such that it can&#x27;t know what `x` is. This gives more power to the user of CPS&#x27;d functions.<p>We can generalize it again by writing<p><pre><code>    forall x . (a -&gt; x) -&gt; F x
</code></pre>
which gives more power to the <i>implementer</i> of the CPS&#x27;d function by letting them return some kind of &quot;effect structure&quot; along with calling the handler. The effect structure is fixed ahead of time but lets us talk about<p><pre><code>    * calling the continuation multiple times
    * returning failure via exceptions
    * producing side effects
    * producing default values when no `a` ever existed
    * etc.
</code></pre>
And in this most general setting Yoneda still comforts us that this is just equivalent to the &quot;direct&quot; form<p><pre><code>    F a</code></pre>