let combine_classes (p : t_partition) m n =
  let rec help2 n xs tas = function
    | (y::_ as ys)::tail ->
        if y=n then
          (* combine xs and ys *)
          merge ((merge xs ys)::tas) tail
        else
          help2 n xs (ys::tas) tail
    | [] -> failwith "combine_classes: m and n have to be representatives in p"
    | _  -> failwith ("combine_classes: p is not a valid partition, it "^
                      "contains an empty class")
  in
  let rec help m n tas = function
    | (x::_ as xs)::tail ->
        if x=m then
          help2 n xs tas tail
        else
          if x=n then
            help2 m xs tas tail
          else
            help m n (xs::tas) tail
    | [] -> failwith "combine_classes: m and n have to be representatives in p"
    | _  -> failwith ("combine_classes: p is not a valid partition, it "^
                      "contains an empty class")
  in
  help m n [] p