Reputation: 29
let add_information info = match info with
(int * int * int) -> int + int + int
;;
let result = add_information (1, 2, 3);;
print_int result;; (* should print 6 here *)
I believe you can match tuples just like you can with lists. Just not sure of the exact format.
Upvotes: 0
Views: 2388
Reputation: 187
you could also declare a new variable saying something like:
let d,e,f = info in
d+e+f;;
Upvotes: 1
Reputation: 9377
Separate with ,
s:
let add_info = function
| a, b, c -> a + b + c
Because tuple matching is irrefutable - that is, there is no way for a match to fail - you can also bind tuples with let
or in a function argument:
let a, b, c = calc_tuple () in a + b + c
Upvotes: 4