let rec zip xs ys =
  match (xs, ys) with
  | ([], _) -> []
  | (_, []) -> []
  | (x :: xs', y :: ys') -> (x, y) :: zip xs' ys'

let rec unzip pairs =
  match pairs with
  | [] -> ([], [])
  | (a, b) :: rest ->
    let (la, lb) = unzip rest in
    (a :: la, b :: lb)

;;

let pairs = zip [1;2;3;4] [10;20;30;40] in
let (xs, ys) = unzip pairs in
List.fold_left (+) 0 xs * List.fold_left (+) 0 ys
