123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570(** This module defines interfaces used in {{!Map}[Map]}. See those docs for a description
of the design.
This module defines module types
[{Creators,Accessors}{1,2,3,_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, [Map] itself
matches [Creators3_with_comparator] but [Accessors3] (without comparator).
*)open!ImportopenTmoduleBinable=Binable0moduleMap=Base.MapmoduleOr_duplicate=Map.Or_duplicatemoduleWith_comparator=Map.With_comparatormoduleWith_first_class_module=Map.With_first_class_modulemoduleWithout_comparator=Map.Without_comparatormoduleTree=Map.Using_comparator.TreemoduletypeKey_plain=sigtypet[@@derivingcompare,sexp_of]endmoduletypeKey=sigtypet[@@derivingcompare,sexp]endmoduletypeKey_binable=sigtypet[@@derivingbin_io,compare,sexp]endmoduletypeKey_hashable=sigtypet[@@derivingcompare,hash,sexp]endmoduletypeKey_binable_hashable=sigtypet[@@derivingbin_io,compare,hash,sexp]endmoduleKey_bin_io=structmoduletypeS=sigtypet[@@derivingbin_io]typecomparator_witnessvalcomparator:(t,comparator_witness)Comparator.tendtype('t,'c)t=(moduleSwithtypet='tandtypecomparator_witness='c)endmoduletypeAccessors_generic=sigincludeMap.Accessors_genericvalkey_set:('k,'cmp,('k,_,'cmp)t->('kkey,'cmpcmp)Base.Set.t)optionsvalvalidate:name:('kkey->string)->'vValidate.check->('k,'v,_)tValidate.checkvalvalidatei:name:('kkey->string)->('kkey*'v)Validate.check->('k,'v,_)tValidate.checkvalquickcheck_observer:'kkeyQuickcheck.Observer.t->'vQuickcheck.Observer.t->('k,'v,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker:('k,'cmp,'kkeyQuickcheck.Shrinker.t->'vQuickcheck.Shrinker.t->('k,'v,'cmp)tQuickcheck.Shrinker.t)optionsendmoduletypeAccessors1=sigincludeMap.Accessors1valkey_set:_t->(key,comparator_witness)Base.Set.tvalvalidate:name:(key->string)->'aValidate.check->'atValidate.checkvalvalidatei:name:(key->string)->(key*'a)Validate.check->'atValidate.checkvalquickcheck_observer:keyQuickcheck.Observer.t->'vQuickcheck.Observer.t->'vtQuickcheck.Observer.tvalquickcheck_shrinker:keyQuickcheck.Shrinker.t->'vQuickcheck.Shrinker.t->'vtQuickcheck.Shrinker.tendmoduletypeAccessors2=sigincludeMap.Accessors2valkey_set:('k,'v)t->('k,comparator_witness)Base.Set.tvalvalidate:name:('a->string)->'bValidate.check->('a,'b)tValidate.checkvalvalidatei:name:('a->string)->('a*'b)Validate.check->('a,'b)tValidate.checkvalquickcheck_observer:'kQuickcheck.Observer.t->'vQuickcheck.Observer.t->('k,'v)tQuickcheck.Observer.tvalquickcheck_shrinker:'kQuickcheck.Shrinker.t->'vQuickcheck.Shrinker.t->('k,'v)tQuickcheck.Shrinker.tendmoduletypeAccessors3=sigincludeMap.Accessors3valkey_set:('k,_,'cmp)t->('k,'cmp)Base.Set.tvalvalidate:name:('a->string)->'bValidate.check->('a,'b,_)tValidate.checkvalvalidatei:name:('a->string)->('a*'b)Validate.check->('a,'b,_)tValidate.checkvalquickcheck_observer:'kQuickcheck.Observer.t->'vQuickcheck.Observer.t->('k,'v,_)tQuickcheck.Observer.tvalquickcheck_shrinker:'kQuickcheck.Shrinker.t->'vQuickcheck.Shrinker.t->('k,'v,_)tQuickcheck.Shrinker.tendmoduletypeAccessors3_with_comparator=sigincludeMap.Accessors3_with_comparatorvalkey_set:comparator:('k,'cmp)Comparator.t->('k,_,'cmp)t->('k,'cmp)Base.Set.tvalvalidate:name:('a->string)->'bValidate.check->('a,'b,_)tValidate.checkvalvalidatei:name:('k->string)->('k*'v)Validate.check->('k,'v,_)tValidate.checkvalquickcheck_observer:'kQuickcheck.Observer.t->'vQuickcheck.Observer.t->('k,'v,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker:comparator:('k,'cmp)Comparator.t->'kQuickcheck.Shrinker.t->'vQuickcheck.Shrinker.t->('k,'v,'cmp)tQuickcheck.Shrinker.tend(** Consistency checks (same as in [Container]). *)moduleCheck_accessors(T:T3)(Tree:T3)(Key:T1)(Cmp:T1)(Options:T3)(_:Accessors_genericwithtype('a,'b,'c)options:=('a,'b,'c)Options.twithtype('a,'b,'c)t:=('a,'b,'c)T.twithtype('a,'b,'c)tree:=('a,'b,'c)Tree.twithtype'akey:='aKey.twithtype'acmp:='aCmp.t)=structendmoduleCheck_accessors1(M:Accessors1)=Check_accessors(structtype('a,'b,'c)t='bM.tend)(structtype('a,'b,'c)t='bM.treeend)(structtype'at=M.keyend)(structtype'at=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_accessors2(M:Accessors2)=Check_accessors(structtype('a,'b,'c)t=('a,'b)M.tend)(structtype('a,'b,'c)t=('a,'b)M.treeend)(structtype'at='aend)(structtype'at=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_accessors3(M:Accessors3)=Check_accessors(structtype('a,'b,'c)t=('a,'b,'c)M.tend)(structtype('a,'b,'c)t=('a,'b,'c)M.treeend)(structtype'at='aend)(structtype'at='aend)(Without_comparator)(M)moduleCheck_accessors3_with_comparator(M:Accessors3_with_comparator)=Check_accessors(structtype('a,'b,'c)t=('a,'b,'c)M.tend)(structtype('a,'b,'c)t=('a,'b,'c)M.treeend)(structtype'at='aend)(structtype'at='aend)(With_comparator)(M)moduletypeCreators_generic=sigincludeMap.Creators_genericvalof_hashtbl_exn:('k,'cmp,('kkey,'v)Hashtbl.t->('k,'v,'cmp)t)options(** Never requires a comparator because it can get one from the input [Set.t]. *)valof_key_set:('kkey,'cmpcmp)Base.Set.t->f:('kkey->'v)->('k,'v,'cmp)tvalquickcheck_generator:('k,'cmp,'kkeyQuickcheck.Generator.t->'vQuickcheck.Generator.t->('k,'v,'cmp)tQuickcheck.Generator.t)optionsendmoduletypeCreators1=sigincludeMap.Creators1valof_hashtbl_exn:(key,'a)Hashtbl.t->'atvalof_key_set:(key,comparator_witness)Base.Set.t->f:(key->'v)->'vtvalquickcheck_generator:keyQuickcheck.Generator.t->'aQuickcheck.Generator.t->'atQuickcheck.Generator.tendmoduletypeCreators2=sigincludeMap.Creators2valof_hashtbl_exn:('a,'b)Hashtbl.t->('a,'b)tvalof_key_set:('a,comparator_witness)Base.Set.t->f:('a->'b)->('a,'b)tvalquickcheck_generator:'aQuickcheck.Generator.t->'bQuickcheck.Generator.t->('a,'b)tQuickcheck.Generator.tendmoduletypeCreators3_with_comparator=sigincludeMap.Creators3_with_comparatorvalof_hashtbl_exn:comparator:('a,'cmp)Comparator.t->('a,'b)Hashtbl.t->('a,'b,'cmp)tvalof_key_set:('a,'cmp)Base.Set.t->f:('a->'b)->('a,'b,'cmp)tvalquickcheck_generator:comparator:('a,'cmp)Comparator.t->'aQuickcheck.Generator.t->'bQuickcheck.Generator.t->('a,'b,'cmp)tQuickcheck.Generator.tendmoduleCheck_creators(T:T3)(Tree:T3)(Key:T1)(Cmp:T1)(Options:T3)(_:Creators_genericwithtype('a,'b,'c)options:=('a,'b,'c)Options.twithtype('a,'b,'c)t:=('a,'b,'c)T.twithtype('a,'b,'c)tree:=('a,'b,'c)Tree.twithtype'akey:='aKey.twithtype'acmp:='aCmp.t)=structendmoduleCheck_creators1(M:Creators1)=Check_creators(structtype('a,'b,'c)t='bM.tend)(structtype('a,'b,'c)t='bM.treeend)(structtype'at=M.keyend)(structtype'at=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_creators2(M:Creators2)=Check_creators(structtype('a,'b,'c)t=('a,'b)M.tend)(structtype('a,'b,'c)t=('a,'b)M.treeend)(structtype'at='aend)(structtype'at=M.comparator_witnessend)(Without_comparator)(M)moduleCheck_creators3_with_comparator(M:Creators3_with_comparator)=Check_creators(structtype('a,'b,'c)t=('a,'b,'c)M.tend)(structtype('a,'b,'c)t=('a,'b,'c)M.treeend)(structtype'at='aend)(structtype'at='aend)(With_comparator)(M)moduletypeCreators_and_accessors_generic=sigincludeCreators_genericincludeAccessors_genericwithtype('a,'b,'c)t:=('a,'b,'c)twithtype('a,'b,'c)tree:=('a,'b,'c)treewithtype'akey:='akeywithtype'acmp:='acmpwithtype('a,'b,'c)options:=('a,'b,'c)optionsendmoduletypeCreators_and_accessors1=sigincludeCreators1includeAccessors1withtype'at:='atwithtype'atree:='atreewithtypekey:=keywithtypecomparator_witness:=comparator_witnessendmoduletypeCreators_and_accessors2=sigincludeCreators2includeAccessors2withtype('a,'b)t:=('a,'b)twithtype('a,'b)tree:=('a,'b)treewithtypecomparator_witness:=comparator_witnessendmoduletypeCreators_and_accessors3_with_comparator=sigincludeCreators3_with_comparatorincludeAccessors3_with_comparatorwithtype('a,'b,'c)t:=('a,'b,'c)twithtype('a,'b,'c)tree:=('a,'b,'c)treeendmoduleMake_S_plain_tree(Key:Comparator.S)=structmoduletypeS=sigtype'at=(Key.t,'a,Key.comparator_witness)Tree.t[@@derivingsexp_of]includeCreators_and_accessors1withtype'at:='atwithtype'atree:='atwithtypekey:=Key.twithtypecomparator_witness:=Key.comparator_witnessmoduleProvide_of_sexp(K:sigtypet[@@derivingof_sexp]endwithtypet:=Key.t):sigtype_t[@@derivingof_sexp]endwithtype'at:='atendendmoduletypeS_plain=sigmoduleKey:sigtypet[@@derivingsexp_of]includeComparator.Swithtypet:=tendtype+'at=(Key.t,'a,Key.comparator_witness)Map.t[@@derivingcompare,sexp_of]includeCreators_and_accessors1withtype'at:='atwithtype'atree:=(Key.t,'a,Key.comparator_witness)Tree.twithtypekey:=Key.twithtypecomparator_witness:=Key.comparator_witnessmoduleProvide_of_sexp(Key:sigtypet[@@derivingof_sexp]endwithtypet:=Key.t):sigtype_t[@@derivingof_sexp]endwithtype'at:='atmoduleProvide_bin_io(Key:sigtypet[@@derivingbin_io]endwithtypet:=Key.t):Binable.S1withtype'at:='atmoduleProvide_hash(Key:Hasher.Swithtypet:=Key.t):sigtype'at[@@derivinghash]endwithtype'at:='atendmoduletypeS=sigmoduleKey:sigtypet[@@derivingsexp]includeComparator.Swithtypet:=tendincludeS_plainwithmoduleKey:=KeyincludeSexpable.S1withtype'at:='atendmoduletypeS_binable=sigmoduleKey:sigtypet[@@derivingbin_io,sexp]includeComparator.Swithtypet:=tendincludeSwithmoduleKey:=KeyincludeBinable.S1withtype'at:='atendmoduletypeFor_deriving=sigincludeBase.Map.For_derivingmoduleM=Base.Map.M(** The following [*bin*] functions support bin-io on base-style maps,
e.g.:
{[ type t = int Map.M(String).t [@@deriving bin_io] ]} *)valbin_shape_m__t:('a,'c)Key_bin_io.t->Bin_prot.Shape.t->Bin_prot.Shape.tvalbin_size_m__t:('a,'c)Key_bin_io.t->'bBin_prot.Size.sizer->('a,'b,'c)tBin_prot.Size.sizervalbin_write_m__t:('a,'c)Key_bin_io.t->'bBin_prot.Write.writer->('a,'b,'c)tBin_prot.Write.writervalbin_read_m__t:('a,'c)Key_bin_io.t->'bBin_prot.Read.reader->('a,'b,'c)tBin_prot.Read.readerval__bin_read_m__t__:('a,'c)Key_bin_io.t->'bBin_prot.Read.reader->(int->('a,'b,'c)t)Bin_prot.Read.reader(** The following [quickcheck*] functions support deriving quickcheck on base-style maps,
e.g.:
{[ type t = int Map.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='kandtypecomparator_witness='cmp)->'vQuickcheck.Generator.t->('k,'v,'cmp)tQuickcheck.Generator.tvalquickcheck_observer_m__t:(moduleQuickcheck_observer_mwithtypet='kandtypecomparator_witness='cmp)->'vQuickcheck.Observer.t->('k,'v,'cmp)tQuickcheck.Observer.tvalquickcheck_shrinker_m__t:(moduleQuickcheck_shrinker_mwithtypet='kandtypecomparator_witness='cmp)->'vQuickcheck.Shrinker.t->('k,'v,'cmp)tQuickcheck.Shrinker.tend