I have a function:
let map_plug (pairs : (char * char) list) input =
let rec plug_aux pairs input =
match pairs with
| [] -> 'A'
| h :: t -> let first, second = h in
match input with
| first -> second
| second -> first
| _ -> plug_aux t input
in plug_aux pairs input
...which takes a list of char pairs, and an input char.
The code I am concerned about is here:
let first, second = h in
match input with
| first -> second
| second -> first
| _ -> plug_aux t input
OCaml tells me that the first case is irrefutable, and that the other cases are not used. I find this behavior puzzling, as I would like to destructure a tuple and bind its elements, and match a variable with those elements; it doesn't seem to work.
I made a simpler example:
let x, y = (3, 4) in
match 4 with
| x -> 7
| y -> 8;;
Line 4, characters 2-3:
Warning 11: this match case is unused.
Testing this in Rust, too, also gives the same error. I realize at this point OCaml must believe that y is simply a shadowed name for a new binding, and thus is matching everything with it.
But I also know that using an if statement allows me to work with the bound elements of the destructured tuple, rather than declare any new variable. Is it possible to use a match statement to match the way I want it to?