I suggest we ...

In a pattern match use the record field name as a default binding if none is provided

In OCaml we can do,

match somrecord with
| {foo; bar; baz} -> foo + bar + baz

If we don't provide a binding, then the field name is used as the default. In F# we still have to write,

match somerecord with
| {foo=foo;bar=bar;baz=baz} -> foo + bar + baz

This is quite a simple syntactic enhancement, however it's very nice to have. It also pushes us to use the (presumably) well chosen record field names for our variables instead of picking a single letter variable name.

Also, in OCaml we get a warning if we don't bind all the record fields in a pattern match, unless we include _. e.g. {foo;bar;_}. This would be a nice thing to have as well, because in a pattern match where we DO want to bind all the fields, we are now told when the record type changes that we need to consider the new field. This is very useful for large projects.

13 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Eric Stokes shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...

F# Language

Feedback and Knowledge Base