I am trying to write a generic iterator that coputes the Fibonacci sequence:
def FibIter[T](fst:T , snd:T)(implicit num:Numeric[T]) = new Iterator[T] {
var fn1 = fst
var fn2 = snd
def hasNext = true
def next() = {
val ret = fn1
fn1 = fn2
fn2 = num.plus(ret,fn2)
ret
}
}
However, the compiler complains about the first two variable assignments:
Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
Does anyone has an idea how to solve this problem? Thank you very much!