Let lst
be a List with tuples which I want to reverse each (The order of the tuples needs to be the same). For example:
[(a,b);(c,d)] -> [(b,a);(d,c)]
I know that it can be done with map:
List.map (fun (a,b) -> (b,a)) [(1,2);(3,4)];;- : (int * int) list = [(2, 1); (4, 3)]
But I´m looking for a way to achieve it with List.fold_left
. My approach is to match the list with []
as a accumulator to concatenate every reversed tuple together, but I keep getting type-Errors:
List.fold_left (fun (a,b) -> (b,a)) [] lst;;