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

Support pattern contracts in match statement #1823

Merged
merged 4 commits into from
Feb 19, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Feb 16, 2024

Depends on #1821.

Match expressions have been extended to accept the full range of patterns (that was reserved to destructuring before). Patterns allow, in particular, to annotate fields with metadata, such as contract annotations or default values. Those were, until now, simply ignored by the new match expressions.

This commit modifies the pattern compilation scheme to handle contracts and default values properly. It follows the current semantics of destructuring (which has been supporting contract in pattern). There is something to be said about default value being merged with the default priority. I'm not sure it aligns well with intuition and other PLs that {foo | default = 1} |> match { {foo ? 2} => foo } } currently fails with a merge conflict instead of returning 1. But at least this PR adds the required machinery. I also think it's mostly forward-compatible with a shift toward a default value that would be used only if the field isn't defined in the original record, as the latter would accept strictly more programs (it's not entirely true, as it would change the meaning of e.g. {foo | default = {}} |> match {{foo ? {bar = 1}} => _, but honestly relying on the fact that the two default values will be merged by the pattern sounds very cursed and twisted...)

@yannham yannham requested review from jneem and vkleen February 16, 2024 20:50
@github-actions github-actions bot temporarily deployed to pull request February 16, 2024 20:54 Inactive
@github-actions github-actions bot temporarily deployed to pull request February 16, 2024 21:20 Inactive
Base automatically changed from fix/adt-contract to master February 19, 2024 17:31
Copy link

dpulls bot commented Feb 19, 2024

🎉 All dependencies have been resolved !

Match expressions have been extended to accept the full range of
patterns (that was reserved to destructuring before). Patterns allow, in
particular, to annotate fields with metadata, such as contract
annotations or default values. Those were, until now, simply ignored by
the new match expressions.

This commit modifies the pattern compilation scheme to handle contracts
and default values properly.
@github-actions github-actions bot temporarily deployed to pull request February 19, 2024 17:44 Inactive
@yannham yannham added this pull request to the merge queue Feb 19, 2024
Merged via the queue into master with commit 0b294a2 Feb 19, 2024
5 checks passed
@yannham yannham deleted the task/match-pattern-contracts branch February 19, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants