This extension helps dealing with warning 57:
File "when.ml", line 28, characters 4-19:
Warning 57: Ambiguous or-pattern variables under guard;
variable x may match different arguments. (See manual section 8.5)
let f = function
| A x, _ (* A 0, A 1 would match here and fail the guard *)
| _, A x when x<>0 -> 1 (* warning 57 *)
| _ -> 2
(* sadly no easy way to have the guard checked for every pattern: *)
let f = function
| A x, _ when x<>0 -> 1
| _, A x when x<>0 -> 1 (* if these were big expressions, we would need to pull out a function for each case to avoid duplication *)
| _ -> 2
Different possibilities (see when.ml
). Decided on the following:
let f = function%distr (* via [ppx_ext_expr.ml]: applies to all cases, no brackets, does not compile w/o ppx *)
| A x, _ | _, A x when x<>0 -> 1
| _ -> 2
Which will result in
let f = function
| A x, _ when x<>0 -> 1 | _, A x when x<>0 -> 1
| _ -> 2