So, would it be possible to extend the ocaml compiler with a simple
feature that let the programmer tell the compiler when he use
an "exhaustive" pattern with record, e.g.
let foo = function
{ field1 = v1; field2 = v2; NOTHING_ELSE} ->
I think this is a great idea (and something I've blogged about before,
as Christophe Troestler points out). The thing I've never come up with
a good proposal for is what would be a pleasant syntax to indicate the
exhaustiveness of the pattern match. I could imagine something terse
like this:
let {! foo = foo; bar = bar; } = x
where the ! indicates that the pattern match should be exhaustive.
Such terse notation would sadly be somewhat obscure.
Another thought I've had for making record matches lighter is to do the
same kind of trick that's done with labeled arguments, i.e., have
let { foo; bar } = x
bind the variable foo to the x.foo, and bind bar to x.bar. Similarly,
it might be nice for:
let foo = 3 and bar = 3. in { foo;bar }
to be equivalent to
let foo = 3 and bar = 3. in { foo = foo; bar = bar }
y