mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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:
@@ -139,8 +139,7 @@ fill_lvm_pv (guestfs_h *g, struct guestfs_lvm_pv *pv, size_t i)
|
||||
| _ -> assert false in
|
||||
|
||||
List.iter (
|
||||
fun { name = name; style = (ret, args, optargs as style);
|
||||
c_optarg_prefix = c_optarg_prefix } ->
|
||||
fun { name; style = (ret, args, optargs as style); c_optarg_prefix } ->
|
||||
pr "/* The %s function prints its parameters to stdout or the\n" name;
|
||||
pr " * file set by internal_test_set_output.\n";
|
||||
pr " */\n";
|
||||
@@ -213,7 +212,7 @@ fill_lvm_pv (guestfs_h *g, struct guestfs_lvm_pv *pv, size_t i)
|
||||
) ptests;
|
||||
|
||||
List.iter (
|
||||
fun { name = name; style = (ret, args, _ as style) } ->
|
||||
fun { name; style = (ret, args, _ as style) } ->
|
||||
if String.sub name (String.length name - 3) 3 <> "err" then (
|
||||
pr "/* Test normal return. */\n";
|
||||
generate_prototype ~extern:false ~semicolon:false ~newline:true
|
||||
|
||||
Reference in New Issue
Block a user