yeti icon indicating copy to clipboard operation
yeti copied to clipboard

Wrong "partial match" error for lists

Open TuongNM opened this issue 11 years ago • 1 comments

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.

TuongNM avatar Sep 16 '13 19:09 TuongNM

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;

mth avatar Sep 16 '13 23:09 mth