123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254open!ImportincludeComparable_intfmoduleInfix=Base.Comparable.InfixmodulePolymorphic_compare=Base.Comparable.Polymorphic_comparemoduleValidate(T:sigtypet[@@derivingcompare,sexp_of]end):Validatewithtypet:=T.t=structmoduleV=ValidateopenMaybe_boundletto_stringt=Base.Sexp.to_string(T.sexp_of_tt)letvalidate_bound~min~maxt=V.bounded~name:to_string~lower:min~upper:max~compare:T.comparet;;letvalidate_lbound~mint=validate_bound~min~max:Unboundedtletvalidate_ubound~maxt=validate_bound~max~min:UnboundedtendmoduleValidate_with_zero(T:sigtypet[@@derivingcompare,sexp_of]valzero:tend)=structmoduleV=Validate(T)includeV(* Preallocate the interesting bounds to minimize allocation in the implementations of
[validate_*]. *)letexcl_zero=Maybe_bound.ExclT.zeroletincl_zero=Maybe_bound.InclT.zeroletvalidate_positivet=validate_lbound~min:excl_zerotletvalidate_non_negativet=validate_lbound~min:incl_zerotletvalidate_negativet=validate_ubound~max:excl_zerotletvalidate_non_positivet=validate_ubound~max:incl_zerotendmoduleWith_zero(T:sigtypet[@@derivingcompare,sexp_of]valzero:tend)=structincludeValidate_with_zero(T)includeBase.Comparable.With_zero(T)endmoduleMap_and_set_binable_using_comparator(T:sigtypet[@@derivingbin_io,compare,sexp]includeComparator.Swithtypet:=tend)=structincludeTmoduleMap=Map.Make_binable_using_comparator(T)moduleSet=Set.Make_binable_using_comparator(T)endmoduleMap_and_set_binable(T:sigtypet[@@derivingbin_io,compare,sexp]end)=Map_and_set_binable_using_comparator(structincludeTincludeComparator.Make(T)end)modulePoly(T:sigtypet[@@derivingsexp]end)=structmoduleC=structincludeTincludeBase.Comparable.Poly(T)endincludeCincludeValidate(C)moduleReplace_polymorphic_compare:Polymorphic_comparewithtypet:=t=CmoduleMap=Map.Make_using_comparator(C)moduleSet=Set.Make_using_comparator(C)endmoduleMake_plain_using_comparator(T:sigtypet[@@derivingsexp_of]includeComparator.Swithtypet:=tend):S_plainwithtypet:=T.tandtypecomparator_witness=T.comparator_witness=structincludeTmoduleM=Base.Comparable.Make_using_comparator(T)includeMincludeValidate(structincludeTincludeMend)moduleReplace_polymorphic_compare:Polymorphic_comparewithtypet:=t=MmoduleMap=Map.Make_plain_using_comparator(T)moduleSet=Set.Make_plain_using_comparator(T)endmoduleMake_plain(T:sigtypet[@@derivingcompare,sexp_of]end)=Make_plain_using_comparator(structincludeTincludeComparator.Make(T)end)moduleMake_using_comparator(T:sigtypet[@@derivingsexp]includeComparator.Swithtypet:=tend):Swithtypet:=T.tandtypecomparator_witness=T.comparator_witness=structincludeTmoduleM=Base.Comparable.Make_using_comparator(T)includeMincludeValidate(structincludeTincludeMend)moduleReplace_polymorphic_compare:Polymorphic_comparewithtypet:=t=MmoduleMap=Map.Make_using_comparator(T)moduleSet=Set.Make_using_comparator(T)endmoduleMake(T:sigtypet[@@derivingcompare,sexp]end):Swithtypet:=T.t=Make_using_comparator(structincludeTincludeComparator.Make(T)end)moduleMake_binable_using_comparator(T:sigtypet[@@derivingbin_io,sexp]includeComparator.Swithtypet:=tend)=structincludeTmoduleM=Base.Comparable.Make_using_comparator(T)includeValidate(structincludeTletcompare=T.comparator.compareend)includeMmoduleReplace_polymorphic_compare:Polymorphic_comparewithtypet:=t=MmoduleMap=Map.Make_binable_using_comparator(T)moduleSet=Set.Make_binable_using_comparator(T)endmoduleMake_binable(T:sigtypet[@@derivingbin_io,compare,sexp]end)=structincludeMake_binable_using_comparator(structincludeTincludeComparator.Make(T)end)endmoduleExtend(M:Base.Comparable.S)(X:sigtypet=M.t[@@derivingsexp]end)=structmoduleT=structincludeMinclude(X:sigtypet=M.t[@@derivingsexp]endwithtypet:=t)endincludeTincludeValidate(T)moduleReplace_polymorphic_compare:Comparisons.Swithtypet:=t=MmoduleMap=Map.Make_using_comparator(T)moduleSet=Set.Make_using_comparator(T)endmoduleExtend_binable(M:Base.Comparable.S)(X:sigtypet=M.t[@@derivingbin_io,sexp]end)=structmoduleT=structincludeMinclude(X:sigtypet=M.t[@@derivingbin_io,sexp]endwithtypet:=t)endincludeTincludeValidate(T)moduleReplace_polymorphic_compare:Comparisons.Swithtypet:=t=MmoduleMap=Map.Make_binable_using_comparator(T)moduleSet=Set.Make_binable_using_comparator(T)endmoduleInherit(C:sigtypet[@@derivingcompare]end)(T:sigtypet[@@derivingsexp]valcomponent:t->C.tend)=Make(structtypet=T.t[@@derivingsexp]letcomparett'=C.compare(T.componentt)(T.componentt')end)include(Base.Comparable:With_compare)moduleStable=structmoduleV1=structmoduletypeS=sigtypecomparabletypecomparator_witnessmoduleMap:Map.Stable.V1.Swithtypekey:=comparablewithtypecomparator_witness:=comparator_witnessmoduleSet:Set.Stable.V1.Swithtypeelt:=comparablewithtypeelt_comparator_witness:=comparator_witnessendmoduleMake(X:Stable_module_types.S0)=structmoduleMap=Map.Stable.V1.Make(X)moduleSet=Set.Stable.V1.Make(X)endendend