ocaml: Replace pattern matching { field = field } with { field }.

If you have a struct containing ‘field’, eg:

  type t = { field : int }

then previously to pattern-match on this type, eg. in function
parameters, you had to write:

  let f { field = field } =
    (* ... use field ... *)

In OCaml >= 3.12 it is possible to abbreviate cases where the field
being matched and the variable being bound have the same name, so now
you can just write:

  let f { field } =
    (* ... use field ... *)

(Similarly for a field prefixed by a Module name you can use
‘{ Module.field }’ instead of ‘{ Module.field = field }’).

This style is widely used inside the OCaml compiler sources, and is
briefer than the long form, so it makes sense to use it.  Furthermore
there was one place in virt-dib where we are already using this new
style, so the old code did not compile on OCaml < 3.12.

See also:
https://forge.ocamlcore.org/docman/view.php/77/112/leroy-cug2010.pdf
This commit is contained in:
Richard W.M. Jones
2017-10-03 21:10:06 +01:00
parent 2cdd2eb795
commit c7651744da
46 changed files with 158 additions and 206 deletions

View File

@@ -614,7 +614,7 @@ throw_out_of_memory (JNIEnv *env, const char *msg)
";
List.iter (
fun { name = name; style = (ret, args, optargs as style);
fun { name; style = (ret, args, optargs as style);
c_function = c_function } ->
pr "\n";
pr "JNIEXPORT ";