wybe icon indicating copy to clipboard operation
wybe copied to clipboard

Allow `where` clauses in case labels

Open pschachte opened this issue 2 years ago • 1 comments

This would be like having guards in case labels in Haskell. Syntax would be something like:

case foo in {
  [] :: ... handle empty list ...
  [?singleton] where prime(singleton) :: ... handle prime singleton ...
  [?head|?tail] :: ... handle other non-empty list cases ...
}

pschachte avatar Nov 15 '22 05:11 pschachte

I like this idea.

Implementation, after parsing this structure should be fairly straightforward. As case statements are flattened into nested if statements, the pattern's test can be prepended to the where's conditions, forming the test for that case.

jimbxb avatar Oct 07 '23 13:10 jimbxb