Open
Description
val nums = Nil.::(4).::(3).::(2).::(1)
nums match {
// Lists of `Int` that starts with `1` and then `2`
case 1 :: 2 :: xs => …
// Lists of length 1
case x :: Nil => …
// Same as `x :: Nil`
case List(x) => …
// The empty list, same as `Nil`
case List() =>
// A list that contains as only element another list that starts with `2`
case List(2 :: xs) => …
}
the last case of case List(2 :: xs)
gives error because the inferred type is List[Int]
but the case signature is expecting List[List[Int]]
. Please correct me if I am wrong. If I am not then how should it be re-written?
Metadata
Metadata
Assignees
Labels
No labels