Domanda

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.

È stato utile?

Soluzione

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

Altri suggerimenti

you could also declare a new variable saying something like:

   let d,e,f = info in 
   d+e+f;;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top