[Libguestfs] [PATCH 2/9] ocaml: Replace pattern matching { field = field } with { field }.

Pino Toscano ptoscano at redhat.com
Wed Oct 4 16:22:18 UTC 2017


On Wednesday, 4 October 2017 14:56:23 CEST Richard W.M. Jones wrote:
> 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.

Oops, sorry.  Considering it was not reported so far, I guess we do not
have many users left on old OCaml versions (old distros, actually).

OOC, did you use a script to detect all these occurrences, or did you
just manually scan through the code?

> diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml
> index 5c5640c67..1be5941c1 100644
> --- a/sysprep/sysprep_operation.ml
> +++ b/sysprep/sysprep_operation.ml
> @@ -172,7 +172,7 @@ let extra_args () =
>    assert !baked;
>  
>    List.flatten (
> -    List.map (fun { extra_args = extra_args } ->
> +    List.map (fun { extra_args } ->
>        List.map (fun { extra_argspec = argspec } -> argspec) extra_args

The last line here can be also simplified too?

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20171004/a1d965df/attachment.sig>


More information about the Libguestfs mailing list