I am having trouble pattern-matching tuples of varing lengths and types.
let test = ((6, 10), (3, "1", 9), ([2; "5"], 4, 7, "8"));;
let rec extract_min_int arg =
match arg with
| (a, b, c) ->
min (extract_lowest_int a) (min (extract_lowest_int b) (extract_lowest_int c))
| (a, b) -> min (extract_lowest_int a) (extract_lowest_int b)
| `int i -> i
| _ -> infinity
;;
extract_min_int test;;
I am expecting this function call to return 2, but I get the following error instead:
Error: This pattern matches values of type 'a * 'b but a pattern was expected which matches values of type 'c * 'd * 'e
I am fairly new to ocaml. This error is denying exactly what I am trying to do, which is match tuples of varying length/type.
What other options do I have here to accomplish this task?
let test =
. And you can't match on it, because it has no structure (looks like that) – Str.