7
在CPS上下文中具有以下類(@cps [Unit]),我將如何實現Seq特徵? 我是否必須將Seq這樣的標準特質放在一邊,只是在cps-context中實現map,flatmap和foreach?爲CPS類實現Seq [T]
class DataFlowVariable[T] {
def apply(): T @cps[Unit] = ...
}
class DataFlowStream[T] extends Seq[T] {
override def iterator: Iterator[T] = new Iterator[T] {
private val iter = queue.iterator
def hasNext: Boolean = iter.hasNext
def next: T = { // needed: next: T @cps[Unit] !
val dfvar = iter.next
// dfvar() // not possible as dvar.apply has type "T @cps[Unit]"
}
}
}
我的問題太神祕了嗎?綜上所述:由於所有在CPS-context中工作的函數都需要返回一個用cps [X]註釋的類型,因此我無法實現像Seq這樣的標準Traits/Interfaces,因爲它們的簽名缺少這些@ cps-annotations。它是否正確? – hotzen 2010-05-03 14:54:32