Exhaustivity of pattern matching a list and Signification of _*
Hello,
-
Pattern matching a list.
If
ls
is a list, isls match { head+:tail => //nonemptyList Nil => //emptyList }
an exhaustive match ?
If
ls
contains a single element will it match to head+: tail
, with head being that element and tail being Nil ?More generally, how do you write an exhaustive pattern match for a list ?
-
What does
_*
represent ?Context : In doing Lab4, I wish to pattern match lists. The compiler warns me that my matches aren't exhaustive and would fail in the case
List(_,_*)
. I was expecting them to be exhaustive and reading my code don't know why they're not.
Hope I've been clear.