'pattern matching on two arguments in ocaml

I am trying to figure out how to match on two arguments in ocaml.

I have a function that takes in two tuples:

let time a b = ...;;
time (34, 4)(5, 6);; // function call

How can I access, say, the first item in the first tuple and add it with the first item in the second tuple? Thanks!



Solution 1:[1]

In addition to the answer from @glennsl, you may find as useful.

let time (a', _ as a) (b', _ as b) = 
  (* ... *)

This lets you destructure both tuples, but also bind a name to each tuple.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris