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

Allow using data constructor defaults in pattern-matching #708

Closed
evhub opened this issue Dec 25, 2022 · 0 comments
Closed

Allow using data constructor defaults in pattern-matching #708

evhub opened this issue Dec 25, 2022 · 0 comments

Comments

@evhub
Copy link
Owner

evhub commented Dec 25, 2022

For a data type defined as

data Name(x="x default", y="y default")

we should compile

Name(got_x) = Name(1)
Name(y=got_y) = Name(y=10)
Name() = Name()

to the equivalent of

Name(got_x, y="y default") = Name(1)
Name(y=got_y, x="x default") = Name(y=10)
Name(x="x default", y="y default") = Name()

probably by looking up the defaults on a __match_defaults__, though note that we'll only be able to do this for data patterns, not class patterns, so as to keep consistency with Python.

Additionally, this will let us pattern-match Expected in the expected way:

Expected(x) = Expected(10)
assert x == 10
Expected(error=err) = Expected(error=some_err)
assert err is some_err
@evhub evhub added this to the v2.2.0 milestone Dec 25, 2022
@evhub evhub added the resolved label Dec 26, 2022
evhub added a commit that referenced this issue Dec 26, 2022
@evhub evhub closed this as completed Dec 26, 2022
@evhub evhub mentioned this issue Dec 28, 2022
evhub added a commit that referenced this issue Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant