For entire Saturday I finally finished assignment 1 but I still got some weird warnings, and to be honest, violate the constraints of only using :: operator.
So I post my implementation of flatten here:
Code: Alles auswählen
import Util._
object Solution {
def flatten[A](xss : List[List[A]]) : List[A] = {
def flat[A](ret: List[A], xss: List[_]) : List[A] = xss match {
case Nil => ret
case ((x: List[A]) :: (ss: List[A])) => flat(ret ::: x, ss)
}
flat(Nil, xss)
}
}
Code: Alles auswählen
solution.scala:8: warning: non variable type-argument A in type pattern List[A] is unchecked since it is eliminated by erasure
case ((x: List[A]) :: (ss: List[A])) => flat(ret ::: x, ss)
^
solution.scala:8: warning: non variable type-argument A in type pattern List[A] is unchecked since it is eliminated by erasure
case ((x: List[A]) :: (ss: List[A])) => flat(ret ::: x, ss)
In addition I used ::: to append list which is forbidden, so how can I append list with only :: ?
Thanks beforehand