I'm trying to write a function, that takes an integer and a triplet and returns an element of the triplet at the given position (exercise 5.3 from Hickey's book). Triplet should be able to contain elements of different types.
I thought, that if I write 3 little functions, each returning a specific element of the triple and make my big function return one of them accordingly, then it would do the trick, but it doesn't work.
I've tried to fiddle with this "eta-expansion" concept, but I didn't get it.
let nth1 (a, _, _) = a
let nth2 (_, b, _) = b
let nth3 (_, _, c) = c
let nth i = match i with
| 1 -> nth1
| 2 -> nth2
| _ -> nth3
let main = printf "%d\n" (nth 1 ("hello", 2, 'c'))
So it should just write "2" here. Any advice?