open List;; let rec uniq l = match l with l1::ls -> l1::(uniq (filter (fun x -> x<>l1) ls)) |[] -> [];; let rec help a l = match l with l1::ls -> if snd a = fst l1 then l1::(fst a, snd l1)::(help a ls) else l1::(help a ls) |[] -> [];; let tran' l = let t = l in let rec tran1' l = match l with l1::ls -> (help l1 t)@(tran1' ls) |[] -> [] in tran1' t;; let rec vcl a b = match a with l1::ls -> (mem l1 b)&&(vcl ls b) |[] -> true;; let rec tran l = if (vcl l (tran' l))&&(vcl (tran' l) l) then (uniq l) else tran (tran' l);; let print a = iter (fun x -> Printf.printf "(%d,%d) " (fst x) (snd x)) a;; print (tran [(1,2);(4,3);(3,1)])