Note that there are some explanatory texts on larger screens.

plurals
  1. POScala implementation of C#-like yield with "for"
    text
    copied!<p>I'm trying to use various Scala implementations of C#-like yield return (i.e. <a href="https://stackoverflow.com/questions/2201882/implementing-yield-yield-return-using-scala-continuations/2215182" title="this implementation">this one</a>) with "for" -constructions such as:</p> <pre><code>private def permutations[T](s: Vector[T]) = { def swap(i: Int, j: Int) { val tmp = s(i) s.set(i, s.get(j)) s.set(j, tmp) } iterator[Vector[T]] { def generate(left: Int, right: Int): Unit @cps[Iteration[Vector[T]]] = { if (left &gt;= right) yieldValue(s) else { generate(left, right) for (i &lt;- left to right) { swap(left, i) generate(left+1, right) swap(left, i) } } } generate(0, s.size-1) } } </code></pre> <p>But this code compiles with error: </p> <pre><code>error: no type parameters for method foreach: (f: (Int) =&gt; U)Unit exist so that it can be applied to arguments ((Int) =&gt; Unit @util.continuations.package.cps[ru.ispras.texterra.nlp.GHMMDisambiguator.Iteration[Vector[T]]]) --- because --- argument expression's type is not compatible with formal parameter type; found : (Int) =&gt; Unit @util.continuations.package.cps[ru.ispras.texterra.nlp.GHMMDisambiguator.Iteration[Vector[T]]] required: (Int) =&gt; ?U for (i &lt;- left to right) { </code></pre> <p>As I understand I have to make all code inside for to be type of <code>() =&gt; Unit</code>, not of <code>() =&gt; Unit @with-annotations</code>. How can I do that?</p> <p>This problem seems to be very common, but I didn't found any mentions in the Internet.</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