123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081moduletypeS=Set_intf.SmoduleMake(Key:Map_intf.Key)(M:Map_intf.Swithtypekey=Key.t)=structincludeStdlib.MoreLabels.Set.Make(structtypet=Key.tletcomparexy=Ordering.to_int(Key.comparexy)end)type'amap='aM.tletto_list=elementsletmemtx=memxtletaddtx=addxtletremovetx=removextletcompareab=Ordering.of_int(compareab)letis_subsett~of_=subsettof_letitert~f=itert~fletmapt~f=mapt~fletfoldt~init~f=foldt~init~fletfor_allt~f=for_allt~fletexistst~f=existst~fletfiltert~f=filtert~fletpartitiont~f=partitiont~fletmin_elt=min_elt_optletmax_elt=max_elt_optletchoose=choose_optletsplitxt=splittxletunion_mapl~f=List.fold_left~init:emptyl~f:(funaccx->lets=fxinunionaccs)letunion_alll=union_mapl~f:(funx->x)exceptionFoundofeltletfindt~f=matchitert~f:(fune->iffethenraise_notrace(Founde)else())with|()->None|exceptionFounde->Someeletto_dynt=Dyn.Set(to_listt|>List.map~f:Key.to_dyn)letchoose_exnt=matchchoosetwith|Somee->e|None->Code_error.raise"Set.choose_exn"[("t",to_dynt)]letof_keys=M.foldi~init:empty~f:(funk_acc->addacck)letto_map=fold~init:M.empty~f:(funkacc->M.setacck())letof_list_mapxs~f=(* We don't [fold_left] & [add] over [xs] because [of_list] has a
specialized implementation *)List.mapxs~f|>of_listend