Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add front-end support for case expressions boolean side conditions #2852

Merged
merged 16 commits into from
Jul 3, 2024

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Jun 21, 2024

This pr introduces:

  1. front-end support (parsing, printing, typechecking) for boolean side conditions for branches of case expressions.
  2. Now if is a reserved keyword.
  3. Multiway if is allowed to have only the else branch. I've also refactored the parser to be simpler.

Example:

 multiCaseBr : Nat :=
    case 1 of
      | zero
        | if 0 < 0 := 3
        | else := 4
      | suc (suc n)
        | if 0 < 0 := 3
        | else := n
      | suc n if 0 < 0 := 3;

The side if branches must satisfy the following.

  1. There must be at least one if branch.
  2. The else branch is optional. If present, it must be the last.

Future work:

  1. Translate side if conditions to Core and extend the exhaustiveness algorithm.
  2. Add side if conditions to function clauses.

@janmasrovira janmasrovira added enhancement New feature or request syntax labels Jun 21, 2024
@janmasrovira janmasrovira added this to the 0.6.3 milestone Jun 21, 2024
@janmasrovira janmasrovira self-assigned this Jun 21, 2024
@janmasrovira janmasrovira force-pushed the syntax-case-side-conditions branch 3 times, most recently from ed4e7db to d1c2e98 Compare June 22, 2024 11:33
@janmasrovira janmasrovira changed the title Add syntax for case expressions boolean side conditions Add front-end support for case expressions boolean side conditions Jun 25, 2024
@janmasrovira janmasrovira force-pushed the syntax-case-side-conditions branch 2 times, most recently from d7706e8 to 8f90a07 Compare June 25, 2024 15:36
@janmasrovira janmasrovira marked this pull request as ready for review June 25, 2024 15:53
@janmasrovira janmasrovira marked this pull request as draft June 25, 2024 16:31
@janmasrovira janmasrovira marked this pull request as draft June 25, 2024 16:31
@janmasrovira janmasrovira marked this pull request as draft June 25, 2024 16:31
janmasrovira added a commit to anoma/juvix-stdlib that referenced this pull request Jun 28, 2024
- We rename `if` to `ite` since `if` will become a keyword in
anoma/juvix#2852
@janmasrovira janmasrovira force-pushed the syntax-case-side-conditions branch 3 times, most recently from 604d7c4 to 4740d22 Compare July 2, 2024 15:22
@janmasrovira janmasrovira marked this pull request as ready for review July 2, 2024 15:22
@paulcadman paulcadman modified the milestones: 0.6.3, 0.6.4 Jul 2, 2024
| else := n
| suc n if 0 < 0 := 3;
end;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test with multiple if conditions for one pattern? I understand this is allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

lukaszcz
lukaszcz previously approved these changes Jul 3, 2024
@janmasrovira janmasrovira merged commit d08bf94 into main Jul 3, 2024
4 checks passed
@janmasrovira janmasrovira deleted the syntax-case-side-conditions branch July 3, 2024 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants