let safe_div a b =
  if b = 0 then Error "division by zero"
  else Ok (a / b)

let sum_safe pairs =
  List.fold_left (fun acc (a, b) ->
    match safe_div a b with
    | Ok q -> acc + q
    | Error _ -> acc
  ) 0 pairs

;;

sum_safe [(10, 2); (20, 4); (30, 0); (50, 5)]
