You are looking for the Cartesian product of two sets.
This question is asked in a thread on the OCaml mailing list. This answer is suggested by Brian Hurt : For
module TypeSet = Set.Make(Type);;
Create for product presentation:
module TypeType = struct type t = Type.t * Type.t;; let compare (x1, x2) (y1, y2) = let r = Type.compare x1 y1 in if r == 0 then Type.compare x2 y2 else r ;; end;; module TypeTypeSet = Set.Make(TypeType);;
Then generate the product with:
let cartesian_product s1 s2 = let fxyt = TypeTypeSet.add (x, y) t in let gxt = TypeSet.fold (fx) s2 t in TypeSet.fold g s1 TypeTypeSet.empty ;;
source share