-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
record punning & record patterns #389
base: dev-0-1-0
Are you sure you want to change the base?
Conversation
} | ||
; | ||
pat_record_body: | ||
| WILDCARD; COMMA? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description COMMA?
allows (| foo = x, _, |)
for a record pattern as well as (| foo = x, _ |)
. Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is intentional. I think there is no reason to forbid a trailing comma after a wildcard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: OCaml also allows ;
after _
in record patterns, but forbids ;
after ..
in object types; i.e. {x; _;}
is acceptable, <x: int; ..;>
is not. This PR's syntax is derived from OCaml's record pattern syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for list [ value1; ]
python also accept trailing comma: one advantage is we can swap item and it will just works. Other reason seems to be human better deal with terminator than separator (last argument was given by an ocp-indent author).
closes #358 and #359.
This PR implements record punning and record patterns in 0.1.0 branch.
Record punning is a short-hand notation for record construction. You can omit a field value if it is a variable reference and the variable has the same name as a record field. E.g.
(| x = x |)
can be written as(| x |)
.Record pattern enables us to pattern match against record values. Record patterns are typed as described in #358:
Some remarks:
--bytecomp
routine is implemented, but is not tested since 0.1.0 does not supporteval_libary_file
in bytecomp mode yet.Exhckecker
. It would be nice to implement it as a separated PR.tests/parsing
tests into inline tests to prevent the possibility that inserting tests changes locations of other tests.