123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544(** This module defines interfaces used in {{!Core.Set}[Set]}. See the
{!Map} docs for a description of the design.
This module defines module types
[{Creators,Accessors}{0,1,2,_generic,_with_comparator}]. It uses check functors to
ensure that each module type is an instance of the corresponding [_generic] one.
We must treat [Creators] and [Accessors] separately, because we sometimes need to
choose different instantiations of their [options]. In particular, [Set] itself
matches [Creators2_with_comparator] but [Accessors2] (without comparator).
*)(*
CRs and comments about [Set] functions do not belong in this file. They belong next
to the appropriate function in set.mli.
*)open!ImportopenTmoduleBinable=Binable0moduleSet=Base.SetmoduleTree=Set.Using_comparator.TreemoduleNamed=Set.NamedmoduleContainer=Base.ContainermoduletypeElt_plain=Set.Elt_plainmoduletypeElt=sigtypet[@@derivingcompare,sexp]endmoduletypeElt_binable=sigtypet[@@derivingbin_io,compare,sexp]endmoduleElt_bin_io=structmoduletypeS=sigtypet[@@derivingbin_io]typecomparator_witnessvalcomparator:(t,comparator_witness)Comparator.tendtype('t,'c)t=(moduleSwithtypet='tandtypecomparator_witness='c)endmoduletypeFor_deriving=sigincludeBase.Set.For_derivingmoduleM=Base.Set.M(** The following [*bin*] functions support bin-io on base-style sets, e.g.:
{[ type t = Set.M(String).t [@@deriving bin_io] ]} *)valbin_shape_m__t:('a,'b)Elt_bin_io.t->Bin_prot.Shape.tvalbin_size_m__t:('a,'b)Elt_bin_io.t->('a,'b)tBin_prot.Size.sizervalbin_write_m__t:('a,'b)Elt_bin_io.t->('a,'b)tBin_prot.Write.writervalbin_read_m__t:('a,'b)Elt_bin_io.t->('a,'b)tBin_prot.Read.readerval__bin_read_m__t__:('a,'b)Elt_bin_io.t->(int->('a,'b)t)Bin_prot.Read.reader(** The following [quickcheck*] functions support deriving quickcheck on base-style
sets, e.g.:
{[ type t = Set.M(String).t [@@deriving quickcheck] ]} *)moduletypeQuickcheck_generator_m=sigincludeComparator.Svalquickcheck_generator:tQuickcheck.Generator.tendmoduletypeQuickcheck_observer_m=sigincludeComparator.Svalquickcheck_observer:tQuickcheck.Observer.tendmoduletypeQuickcheck_shrinker_m=sigincludeComparator.Svalquickcheck_shrinker:tQuickcheck.Shrinker.tendvalquickcheck_generator_m__t:(moduleQuickcheck_generator_mwithtypet='aandtypecomparator_witness='cmp)->('a,'cmp)tQuickcheck.Generator.tvalquickcheck_observer_m__t:(moduleQuickcheck_observer_mwithtypet='aandtypecomparator_witness='cmp)->('a,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker_m__t:(moduleQuickcheck_shrinker_mwithtypet='aandtypecomparator_witness='cmp)->('a,'cmp)tQuickcheck.Shrinker.tendmoduleWithout_comparator=Set.Without_comparatormoduleWith_comparator=Set.With_comparatormoduleWith_first_class_module=Set.With_first_class_modulemoduleContinue_or_stop=Container.Continue_or_stopmoduleMerge_to_sequence_element=Sequence.Merge_with_duplicates_elementmoduletypeAccessors_generic=sigincludeSet.Accessors_genericvalto_map:('a,'cmp,('a,'cmp)t->f:('aelt->'b)->('aelt,'b,'cmpcmp)Base.Map.t)optionsvalquickcheck_observer:'aeltQuickcheck.Observer.t->('a,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker:('a,'cmp,'aeltQuickcheck.Shrinker.t->('a,'cmp)tQuickcheck.Shrinker.t)optionsendmoduletypeAccessors0=sigincludeSet.Accessors0valto_map:t->f:(elt->'data)->(elt,'data,comparator_witness)Base.Map.tvalquickcheck_observer:eltQuickcheck.Observer.t->tQuickcheck.Observer.tvalquickcheck_shrinker:eltQuickcheck.Shrinker.t->tQuickcheck.Shrinker.tendmoduletypeAccessors1=sigincludeSet.Accessors1valto_map:'at->f:('a->'b)->('a,'b,comparator_witness)Base.Map.tvalquickcheck_observer:'aQuickcheck.Observer.t->'atQuickcheck.Observer.tvalquickcheck_shrinker:'aQuickcheck.Shrinker.t->'atQuickcheck.Shrinker.tendmoduletypeAccessors2=sigincludeSet.Accessors2valto_map:('a,'cmp)t->f:('a->'b)->('a,'b,'cmp)Base.Map.tvalquickcheck_observer:'aQuickcheck.Observer.t->('a,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker:'aQuickcheck.Shrinker.t->('a,'cmp)tQuickcheck.Shrinker.tendmoduletypeAccessors2_with_comparator=sigincludeSet.Accessors2_with_comparatorvalto_map:comparator:('a,'cmp)Comparator.t->('a,'cmp)t->f:('a->'b)->('a,'b,'cmp)Base.Map.tvalquickcheck_observer:'aQuickcheck.Observer.t->('a,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker:comparator:('a,'cmp)Comparator.t->'aQuickcheck.Shrinker.t->('a,'cmp)tQuickcheck.Shrinker.tend(** Consistency checks (same as in [Container]). *)moduleCheck_accessors(T:T2)(Tree:T2)(Elt:T1)(Named:T2)(Cmp:T1)(Options:T3)(_:Accessors_genericwithtype('a,'b,'c)options:=('a,'b,'c)Options.twithtype('a,'b)t:=('a,'b)T.twithtype('a,'b)tree:=('a,'b)Tree.twithtype'aelt:='aElt.twithtype'cmpcmp:='cmpCmp.twithtype('a,'b)named:=('a,'b)Named.t)=structendmoduleCheck_accessors0(M:Accessors0)=Check_accessors(structtype('a,'b)t=M.tend)(structtype('a,'b)t=M.treeend)(structtype'at=M.eltend)(structtype('a,'b)t=M.namedend)(structtype'at=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_accessors1(M:Accessors1)=Check_accessors(structtype('a,'b)t='aM.tend)(structtype('a,'b)t='aM.treeend)(structtype'at='aend)(structtype('a,'b)t='aM.namedend)(structtype'at=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_accessors2(M:Accessors2)=Check_accessors(structtype('a,'b)t=('a,'b)M.tend)(structtype('a,'b)t=('a,'b)M.treeend)(structtype'at='aend)(structtype('a,'b)t=('a,'b)M.namedend)(structtype'at='aend)(Without_comparator)(M)moduleCheck_accessors2_with_comparator(M:Accessors2_with_comparator)=Check_accessors(structtype('a,'b)t=('a,'b)M.tend)(structtype('a,'b)t=('a,'b)M.treeend)(structtype'at='aend)(structtype('a,'b)t=('a,'b)M.namedend)(structtype'at='aend)(With_comparator)(M)moduletypeCreators_generic=sigincludeSet.Creators_genericvalof_hash_set:('a,'cmp,'aeltHash_set.t->('a,'cmp)t)optionsvalof_hashtbl_keys:('a,'cmp,('aelt,_)Hashtbl.t->('a,'cmp)t)options(** Never requires a comparator because it can get one from the input [Map.t]. *)valof_map_keys:('aelt,_,'cmpcmp)Base.Map.t->('a,'cmp)tvalquickcheck_generator:('a,'cmp,'aeltQuickcheck.Generator.t->('a,'cmp)tQuickcheck.Generator.t)optionsendmoduletypeCreators0=sigincludeSet.Creators0valof_hash_set:eltHash_set.t->tvalof_hashtbl_keys:(elt,_)Hashtbl.t->tvalof_map_keys:(elt,_,comparator_witness)Base.Map.t->tvalquickcheck_generator:eltQuickcheck.Generator.t->tQuickcheck.Generator.tendmoduletypeCreators1=sigincludeSet.Creators1valof_hash_set:'aHash_set.t->'atvalof_hashtbl_keys:('a,_)Hashtbl.t->'atvalof_map_keys:('a,_,comparator_witness)Base.Map.t->'atvalquickcheck_generator:'aQuickcheck.Generator.t->'atQuickcheck.Generator.tendmoduletypeCreators2=sigincludeSet.Creators2valof_hash_set:'aHash_set.t->('a,'cmp)tvalof_hashtbl_keys:('a,_)Hashtbl.t->('a,'cmp)tvalof_map_keys:('a,_,'cmp)Base.Map.t->('a,'cmp)tvalquickcheck_generator:'aQuickcheck.Generator.t->('a,'cmp)tQuickcheck.Generator.tendmoduletypeCreators2_with_comparator=sigincludeSet.Creators2_with_comparatorvalof_hash_set:comparator:('a,'cmp)Comparator.t->'aHash_set.t->('a,'cmp)tvalof_hashtbl_keys:comparator:('a,'cmp)Comparator.t->('a,_)Hashtbl.t->('a,'cmp)tvalof_map_keys:('a,_,'cmp)Base.Map.t->('a,'cmp)tvalquickcheck_generator:comparator:('a,'cmp)Comparator.t->'aQuickcheck.Generator.t->('a,'cmp)tQuickcheck.Generator.tendmoduleCheck_creators(T:T2)(Tree:T2)(Elt:T1)(Cmp:T1)(Options:T3)(_:Creators_genericwithtype('a,'b,'c)options:=('a,'b,'c)Options.twithtype('a,'b)t:=('a,'b)T.twithtype('a,'b)tree:=('a,'b)Tree.twithtype'aelt:='aElt.twithtype'cmpcmp:='cmpCmp.t)=structendmoduleCheck_creators0(M:Creators0)=Check_creators(structtype('a,'b)t=M.tend)(structtype('a,'b)t=M.treeend)(structtype'at=M.eltend)(structtype'cmpt=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_creators1(M:Creators1)=Check_creators(structtype('a,'b)t='aM.tend)(structtype('a,'b)t='aM.treeend)(structtype'at='aend)(structtype'cmpt=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_creators2(M:Creators2)=Check_creators(structtype('a,'b)t=('a,'b)M.tend)(structtype('a,'b)t=('a,'b)M.treeend)(structtype'at='aend)(structtype'cmpt='cmpend)(Without_comparator)(M)moduleCheck_creators2_with_comparator(M:Creators2_with_comparator)=Check_creators(structtype('a,'b)t=('a,'b)M.tend)(structtype('a,'b)t=('a,'b)M.treeend)(structtype'at='aend)(structtype'cmpt='cmpend)(With_comparator)(M)moduletypeCreators_and_accessors_generic=sigincludeAccessors_genericincludeCreators_genericwithtype('a,'b,'c)options:=('a,'b,'c)optionswithtype('a,'b)t:=('a,'b)twithtype('a,'b)tree:=('a,'b)treewithtype'aelt:='aeltwithtype'cmpcmp:='cmpcmpendmoduletypeCreators_and_accessors0=sigincludeAccessors0includeCreators0withtypet:=twithtypetree:=treewithtypeelt:=eltwithtypecomparator_witness:=comparator_witnessendmoduletypeCreators_and_accessors1=sigincludeAccessors1includeCreators1withtype'at:='atwithtype'atree:='atreewithtypecomparator_witness:=comparator_witnessendmoduletypeCreators_and_accessors2=sigincludeAccessors2includeCreators2withtype('a,'b)t:=('a,'b)twithtype('a,'b)tree:=('a,'b)treeendmoduletypeCreators_and_accessors2_with_comparator=sigincludeAccessors2_with_comparatorincludeCreators2_with_comparatorwithtype('a,'b)t:=('a,'b)twithtype('a,'b)tree:=('a,'b)treeendmoduleMake_S_plain_tree(Elt:Comparator.S)=structmoduletypeS=sigtypet=(Elt.t,Elt.comparator_witness)Tree.t[@@derivingcompare,sexp_of]typenamed=(Elt.t,Elt.comparator_witness)Tree.Named.tincludeCreators_and_accessors0withtype('a,'b)set:=('a,'b)Tree.twithtypet:=twithtypetree:=twithtypeelt:=Elt.twithtypenamed:=namedwithtypecomparator_witness:=Elt.comparator_witnessmoduleProvide_of_sexp(Elt:sigtypet[@@derivingof_sexp]endwithtypet:=Elt.t):sigtypet[@@derivingof_sexp]endwithtypet:=tendendmoduletypeS_plain=sigmoduleElt:sigtypet[@@derivingsexp_of]includeComparator.Swithtypet:=tendtypet=(Elt.t,Elt.comparator_witness)Base.Set.t[@@derivingcompare,sexp_of]typenamed=(Elt.t,Elt.comparator_witness)Named.tincludeCreators_and_accessors0withtype('a,'b)set:=('a,'b)Base.Set.twithtypet:=twithtypetree:=(Elt.t,Elt.comparator_witness)Tree.twithtypeelt:=Elt.twithtypenamed:=namedwithtypecomparator_witness:=Elt.comparator_witnessmoduleProvide_of_sexp(Elt:sigtypet[@@derivingof_sexp]endwithtypet:=Elt.t):sigtypet[@@derivingof_sexp]endwithtypet:=tmoduleProvide_bin_io(Elt:sigtypet[@@derivingbin_io]endwithtypet:=Elt.t):Binable.Swithtypet:=tmoduleProvide_hash(Elt:Hasher.Swithtypet:=Elt.t):sigtypet[@@derivinghash]endwithtypet:=tendmoduletypeS=sigmoduleElt:sigtypet[@@derivingsexp]includeComparator.Swithtypet:=tendincludeS_plainwithmoduleElt:=EltincludeSexpable.Swithtypet:=tendmoduletypeS_binable=sigmoduleElt:sigtypet[@@derivingsexp,bin_io]includeComparator.Swithtypet:=tendincludeSwithmoduleElt:=EltincludeBinable.Swithtypet:=tend