Implementing Seq [T] for CPS Classes

Having the following class that is in the CPS context (@cps [Unit]), how can I implement Seq-trait? Should I leave the standard features like Seq and just implement the map, flat map and foreach in cps context?

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]" } } } 
+7
scala continuations
source share
1 answer

OK, as I understand it, implementing interfaces / features like Seq is not possible. However, since Scala rewrites for syntax- for loops into regular foreach / map-calls, it works just fine to just implement map and foreach with the required cps annotation. filter and co should also work.

However, any advice on how to implement features in a cps context is greatly appreciated.

+1
source share

All Articles