我在这里想念什么?这是我得到的错误......
错误:类型不匹配;找到:List[Double](在方法 calculateHaarWaveletI 中)]
必需:列表[scala.Double]
Console.println(list2Tuples(ls.take(n)))
这是我的代码..
object HaarWavelet {
def calculateHaarWavelet(ls: List[Double]): List[Double] = {
if (ls.length % 2 != 0) throw new RuntimeException("Need even number of elements to calculate HaarWavelet")
calculateHaarWaveletI(ls, ls.length)
def calculateHaarWaveletI[Double](ls: List[Double], n: Int): List[Double] = {
Console.println(list2Tuples(ls.take(n)))
null
}
null
}
def processTuple(x: (Double, Double)): (Double, Double) = {
val f = (x._1 + x._2) / 2
(f, x._1 - f)
}
def list2Tuples(ls: List[Double]): List[(Double, Double)] = {
if (ls.isEmpty) return List()
(ls.head, ls.tail) match {
case (_, Nil) => List()
case (x, y) => List((x, y.head)) ::: list2Tuples(y.tail)
}
}
def main(args: Array[String]) {
Console.println("Starting....")
Console.println(calculateHaarWavelet(List(8.0, 4.0)))
Console.println("Done....")
}
}