Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow using data constructor defaults in pattern-matching #708

@evhub

Description

@evhub

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions