Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To quote the <a href="http://en.wikipedia.org/wiki/Delimited_continuation" rel="nofollow">wikipedia</a>:</p> <blockquote> <p>a delimited continuation, composable continuation or partial continuation, is a "slice" of a continuation frame that has been reified into a function. </p> </blockquote> <p>Scala syntax for this is:</p> <pre><code>// Assuming g: X =&gt; anything reset { A g(shift { (f: (X) =&gt; Y) =&gt; /* code using function f */ }) B } </code></pre> <p>A <em>continuation frame</em> above is everything that would be executed <em>after</em> the <code>shift</code> up until the end of the block delimited by <code>reset</code>. That includes calling the function <code>g</code>, since it would only be called <em>after</em> evaluating <code>shift</code>, plus all the code in <code>B</code>.</p> <p>The function <code>g</code> is not required -- one could be calling a method instead, or completely ignore the result of <code>shift</code>. I show it just to make clear that the <code>shift</code> call returns a value that can be used.</p> <p>In other words, that continuation frame becomes the following function:</p> <pre><code>// Assuming g: X =&gt; anything def f: (X) =&gt; Y = { x =&gt; g(x) B } </code></pre> <p>And the whole reset body becomes this:</p> <pre><code>// Assuming g: X =&gt; anything A def f: (X) =&gt; Y = { x =&gt; g(x) B } /* code using function f */ </code></pre> <p>Note that the last statement in <code>B</code> must have type <code>Y</code>. The result of the computation is the result of the contents of the <code>shift</code> block, as would happen with that translation above.</p> <p>If you want more precision, <a href="http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf" rel="nofollow">check the paper</a> that describes delimited continuations in Scala. The exact types can be found on the <a href="http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/index.html#scala.util.continuations.package" rel="nofollow">API documentation</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload