Open TuongNM opened 11 years ago
On Mon, 16 Sep 2013, TuongNM wrote:
The following code should match all possible cases:
isEmptyList = \case of []: "empty list"; x::xs: "non-empty list with head: (x) and tail: (xs)" esac;
The empty list as well as any list with at least one element is covered. But yeti produces an error.
Partial match: []
I guess the code analyzer for pattern matching on lists needs to check for the cases where the empty list as well as "x::xs"-llike constructs are present and thereby recognize that all possible list cases have been matched.
Yes, this is known problem, WONTFIX before 1.0 release. The reason for current behaviour is that I don't want to make the compiler more restrictive later, when it would break existing code - so the case expression is overly restrictive now.
Workaround is to rewrite the case of in a way, that ends with wildcard match on the list:
isEmptyList = \case of: x :: xs: "non-empty list with head: (x) and tail: (xs)"; _: "empty list"; esac;
The following code should match all possible cases:
The empty list as well as any list with at least one element is covered. But yeti produces an error.
I guess the code analyzer for pattern matching on lists needs to check for the cases where the empty list as well as "x::xs"-llike constructs are present and thereby recognize that all possible list cases have been matched.