scala/ScalaBook/chapter-03/append.scala
//def append[A](a:List[A],b:List[A]):List[A] =
// a match {
// case Nil => b
// case x::xs => x:: append(xs,b)
// }
def appendC[A](a:List[A], b:List[A]):List[A] = {
def append2[A,B](a:List[A], b:List[A],
cont: (List[A] => B) ):B =
a match {
case Nil => cont(b)
case x::xs => append2(xs,b,
((r:List[A]) => cont(x::r)))
}
append2(a,b,((r:List[A]) => r))
}
var A = List(1,2,3)
var B = List(4,5,6)
println(appendC(A,B))
def Reverse[α](A:List[α]): List[α] =
A match {
case Nil => Nil
case x::xs => Reverse(xs):::List(x)
}
print(Reverse(A))