I did some research and I can see that the List.zip function takes two lists and returns one list of tuples, but how do you change one list to a list of tuples?
let rec combinePair xs =
match xs with
| [] -> []
| [x1] -> []
| x1::x2::x3::xs -> [(x1, x2)]
| x1::x2::xs -> [(x1, x2)]
If there is an odd number of elements in the list, the last element should be discarded; if there is an even number of elements, they should be returned as a list of tuples. for instance
combinePair [x1; x2; x3; x4] = [(x1, x2); (x3, x4)]
source
share