Scala实现类C的收益率;至于;

Scala实现类C的收益率;至于;,scala,scala-2.8,yield,continuations,yield-return,Scala,Scala 2.8,Yield,Continuations,Yield Return,我正在尝试使用各种类似C#的收益率回报(即)和“for”结构的Scala实现,例如: 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): Un

我正在尝试使用各种类似C#的收益率回报(即)和“for”结构的Scala实现,例如:

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 >= right)
        yieldValue(s)

      else {
        generate(left, right)
        for (i <- left to right) {
          swap(left, i)
          generate(left+1, right)
          swap(left, i)
        }
      }
    }

    generate(0, s.size-1)
  } 
}
private def置换[T](s:Vector[T])={
def交换(i:Int,j:Int){
val tmp=s(i)
s、 集合(i,s.get(j))
s、 组(j,tmp)
}
迭代器[向量[T]]{
def generate(左:Int,右:Int):单位@cps[Iteration[Vector[T]]]={
如果(左>=右)
产量价值(s)
否则{
生成(左、右)
for(iu)单位存在,以便将其应用于参数((Int)=>Unit@util.continuations.package.cps[ru.ispras.texterra.nlp.GHMMDisambiguator.Iteration[Vector[T]]))
---因为---
参数表达式的类型与形式参数类型不兼容;
发现:(Int)=>Unit@util.continuations.package.cps[ru.ispras.texterra.nlp.GHMMDisambiguator.Iteration[Vector[T]]
必需:(Int)=>?U
对于(i单位
,而不是带有注释的()=>Unit@单位。我怎么做


这个问题似乎很常见,但我在互联网上没有发现任何提及。

如果您使用链接示例中的
迭代器类型,您的
generate
方法是否需要以下返回类型,而不是您的返回类型

Unit @cps[Iteration[Vector[T]],Iteration[Vector[T]]]

恐怕我对这方面没有太多经验,但它看起来很像你在
迭代器中调用的方法,必须在注释上有两个(相同的)类型参数。

:type cps=cpsParam[a,a],所以我认为scala团队已经将cps重命名为cpsParam,并添加了类型cps,即使我使用@cps[Iteration[Vector[t]],迭代[Vector[T]]问题仍然存在哦,对不起!我只是从我在那里看到的东西开始工作。祝你好运!也许我遗漏了什么,但是那个例子中的大括号似乎不匹配。你如何能够在那里调用generate?它在嵌套的作用域中。我通过删除一个额外的大括号解决了这两个问题。这个问题是fol的重复lowing提供了一个答案:
Unit @cps[Iteration[Vector[T]],Iteration[Vector[T]]]