123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285openBasemoduleHigher_kinded_module_types(Higher_kinded:T1)=struct(** These are the signatures implemented by the [Make] family of functors. *)(*$ Higher_kinded_cinaps.print_module_type_s () *)moduletypeS=sigtype'attypehigher_kindedvalinject:'at->('a->higher_kinded)Higher_kinded.tvalproject:('a->higher_kinded)Higher_kinded.t->'atendmoduletypeS2=sigtype('a,'z)ttypehigher_kindedvalinject:('a,'z)t->('a->'z->higher_kinded)Higher_kinded.tvalproject:('a->'z->higher_kinded)Higher_kinded.t->('a,'z)tendmoduletypeS3=sigtype('a,'y,'z)ttypehigher_kindedvalinject:('a,'y,'z)t->('a->'y->'z->higher_kinded)Higher_kinded.tvalproject:('a->'y->'z->higher_kinded)Higher_kinded.t->('a,'y,'z)tendmoduletypeS4=sigtype('a,'x,'y,'z)ttypehigher_kindedvalinject:('a,'x,'y,'z)t->('a->'x->'y->'z->higher_kinded)Higher_kinded.tvalproject:('a->'x->'y->'z->higher_kinded)Higher_kinded.t->('a,'x,'y,'z)tendmoduletypeS5=sigtype('a,'w,'x,'y,'z)ttypehigher_kindedvalinject:('a,'w,'x,'y,'z)t->('a->'w->'x->'y->'z->higher_kinded)Higher_kinded.tvalproject:('a->'w->'x->'y->'z->higher_kinded)Higher_kinded.t->('a,'w,'x,'y,'z)tendmoduletypeS6=sigtype('a,'v,'w,'x,'y,'z)ttypehigher_kindedvalinject:('a,'v,'w,'x,'y,'z)t->('a->'v->'w->'x->'y->'z->higher_kinded)Higher_kinded.tvalproject:('a->'v->'w->'x->'y->'z->higher_kinded)Higher_kinded.t->('a,'v,'w,'x,'y,'z)tendmoduletypeS7=sigtype('a,'u,'v,'w,'x,'y,'z)ttypehigher_kindedvalinject:('a,'u,'v,'w,'x,'y,'z)t->('a->'u->'v->'w->'x->'y->'z->higher_kinded)Higher_kinded.tvalproject:('a->'u->'v->'w->'x->'y->'z->higher_kinded)Higher_kinded.t->('a,'u,'v,'w,'x,'y,'z)tendmoduletypeS8=sigtype('a,'t,'u,'v,'w,'x,'y,'z)ttypehigher_kindedvalinject:('a,'t,'u,'v,'w,'x,'y,'z)t->('a->'t->'u->'v->'w->'x->'y->'z->higher_kinded)Higher_kinded.tvalproject:('a->'t->'u->'v->'w->'x->'y->'z->higher_kinded)Higher_kinded.t->('a,'t,'u,'v,'w,'x,'y,'z)tend(*$*)(** These are the signatures implemented by the [Make_monad] and
[Make_monad_using_witness] families of functors. *)(*$ Higher_kinded_cinaps.print_module_type_monad () *)moduletypeMonad=sigincludeSincludeMonad.Swithtype'at:=('a->higher_kinded)Higher_kinded.tendmoduletypeMonad2=sigincludeS2includeMonad.S2withtype('a,'b)t:=('a->'b->higher_kinded)Higher_kinded.tendmoduletypeMonad3=sigincludeS3includeMonad.S3withtype('a,'b,'c)t:=('a->'b->'c->higher_kinded)Higher_kinded.tend(*$*)endmoduletypeHigher_kinded=sig(** This library allows you to use higher-kinded types in OCaml. See the README for a
short tutorial on what that means and how to use it. *)(** {2 Types} *)(** If [A] implements the signature [S], [(a, A.witness1) t] is equivalent to [a A.t].
*)type'at(*$ Higher_kinded_cinaps.print_type_aliases ~include_comments:true *)(** If [A] implements the signature [S],
[('a, A.higher_kinded) t1]
is equivalent to
['a A.t]. *)type('a,'witness)t1=('a->'witness)t(** If [A] implements the signature [S2],
[('a, 'b, A.higher_kinded) t2]
is equivalent to
[('a, 'b) A.t]. *)type('a,'b,'witness)t2=('a,'b->'witness)t1(** If [A] implements the signature [S3],
[('a, 'b, 'c, A.higher_kinded) t3]
is equivalent to
[('a, 'b, 'c) A.t]. *)type('a,'b,'c,'witness)t3=('a,'b,'c->'witness)t2(** If [A] implements the signature [S4],
[('a, 'b, 'c, 'd, A.higher_kinded) t4]
is equivalent to
[('a, 'b, 'c, 'd) A.t]. *)type('a,'b,'c,'d,'witness)t4=('a,'b,'c,'d->'witness)t3(** If [A] implements the signature [S5],
[('a, 'b, 'c, 'd, 'e, A.higher_kinded) t5]
is equivalent to
[('a, 'b, 'c, 'd, 'e) A.t]. *)type('a,'b,'c,'d,'e,'witness)t5=('a,'b,'c,'d,'e->'witness)t4(** If [A] implements the signature [S6],
[('a, 'b, 'c, 'd, 'e, 'f, A.higher_kinded) t6]
is equivalent to
[('a, 'b, 'c, 'd, 'e, 'f) A.t]. *)type('a,'b,'c,'d,'e,'f,'witness)t6=('a,'b,'c,'d,'e,'f->'witness)t5(** If [A] implements the signature [S7],
[('a, 'b, 'c, 'd, 'e, 'f, 'g, A.higher_kinded) t7]
is equivalent to
[('a, 'b, 'c, 'd, 'e, 'f, 'g) A.t]. *)type('a,'b,'c,'d,'e,'f,'g,'witness)t7=('a,'b,'c,'d,'e,'f,'g->'witness)t6(** If [A] implements the signature [S8],
[('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, A.higher_kinded) t8]
is equivalent to
[('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h) A.t]. *)type('a,'b,'c,'d,'e,'f,'g,'h,'witness)t8=('a,'b,'c,'d,'e,'f,'g,'h->'witness)t7(*$*)(** {2 Signatures} *)includemoduletypeofHigher_kinded_module_types(structtypenonrec'at='atend)(** {2 Functors} *)(** This is the meat of the library. Use these functors to implement the higher_kinded
interface. *)(*$ Higher_kinded_cinaps.print_functor_types () *)moduleMake(X:sigtype'atend):Swithtype'at:='aX.tmoduleMake2(X:sigtype('a,'z)tend):S2withtype('a,'z)t:=('a,'z)X.tmoduleMake3(X:sigtype('a,'y,'z)tend):S3withtype('a,'y,'z)t:=('a,'y,'z)X.tmoduleMake4(X:sigtype('a,'x,'y,'z)tend):S4withtype('a,'x,'y,'z)t:=('a,'x,'y,'z)X.tmoduleMake5(X:sigtype('a,'w,'x,'y,'z)tend):S5withtype('a,'w,'x,'y,'z)t:=('a,'w,'x,'y,'z)X.tmoduleMake6(X:sigtype('a,'v,'w,'x,'y,'z)tend):S6withtype('a,'v,'w,'x,'y,'z)t:=('a,'v,'w,'x,'y,'z)X.tmoduleMake7(X:sigtype('a,'u,'v,'w,'x,'y,'z)tend):S7withtype('a,'u,'v,'w,'x,'y,'z)t:=('a,'u,'v,'w,'x,'y,'z)X.tmoduleMake8(X:sigtype('a,'t,'u,'v,'w,'x,'y,'z)tend):S8withtype('a,'t,'u,'v,'w,'x,'y,'z)t:=('a,'t,'u,'v,'w,'x,'y,'z)X.tmoduleMake_monad(M:Monad.S):Monadwithtype'at:='aM.tmoduleMake_monad2(M:Monad.S2):Monad2withtype('a,'b)t:=('a,'b)M.tmoduleMake_monad3(M:Monad.S3):Monad3withtype('a,'b,'c)t:=('a,'b,'c)M.tmoduleMake_monad_using_witness(M:Monad.S)(X:Swithtype'at:='aM.t):Monadwithtype'at:='aM.twithtypehigher_kinded:=X.higher_kindedmoduleMake_monad_using_witness2(M:Monad.S2)(X:S2withtype('a,'b)t:=('a,'b)M.t):Monad2withtype('a,'b)t:=('a,'b)M.twithtypehigher_kinded:=X.higher_kindedmoduleMake_monad_using_witness3(M:Monad.S3)(X:S3withtype('a,'b,'c)t:=('a,'b,'c)M.t):Monad3withtype('a,'b,'c)t:=('a,'b,'c)M.twithtypehigher_kinded:=X.higher_kinded(*$*)(** {2 Implementations} *)(** [Base], [Core], and [Async] don't depend on [Higher_kinded], so we put these
implementations here instead of in the respective modules where they might have been
a nicer fit. *)moduleIdent:Swithtype'at:='amoduleArray:Swithtype'at:='aArray.tmoduleEither:S2withtype('a,'b)t:=('a,'b)Either.tmoduleHash_set:Swithtype'at:='aHash_set.tmoduleHashtbl:S2withtype('a,'b)t:=('a,'b)Hashtbl.tmoduleLazy:Swithtype'at:='aLazy.tmoduleList:Swithtype'at:='aList.tmoduleMap:S3withtype('a,'b,'c)t:=('a,'b,'c)Map.tmoduleOption:Swithtype'at:='aOption.tmoduleQueue:Swithtype'at:='aQueue.tmoduleRef:Swithtype'at:='aRef.tmoduleResult:S2withtype('a,'e)t:=('a,'e)Result.tmoduleSet:S2withtype('a,'b)t:=('a,'b)Set.tmoduleSequence:Swithtype'at:='aSequence.tmoduleType_equal:S2withtype('a,'b)t:=('a,'b)Type_equal.t(** [t] itself has one type parameter, so we might as well implement [S] right here. *)includeSwithtype'at:='atend