i try to transform this code into the CPS form:
def sum ( lst : List [ Int ]) : Int = lst match {
case Nil => 0
case first :: rest => first + sum ( rest )
}
def sumC1(lst : List [ Int ], k : Int => Unit ) : Unit = lst match {
case lst => k(sum(lst))
}
I ma new to scala and got very big problems undertand the syntax. it would be very helpful if you give me some syntax to solve this task
Here is my code with a typ mismatch:
def sum(lst: List[Int])(cont: Int => Int): Int = lst match {
case Nil => cont(0)
case first :: rest => sum(lst){rest => cont(first + rest) }
}
def sumC1(lst: List[Int], k: Int => Unit): Unit = lst match {
case lst => k(sum(lst))
}
sumC1(List(1, 2, 3), (v: Int) => println(v))