123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240open!ImportincludeApplicative_intf(** This module serves mostly as a partial check that [S2] and [S] are in sync, but
actually calling it is occasionally useful. *)moduleS_to_S2(X:S):S2withtype('a,'e)t='aX.t=structtype('a,'e)t='aX.tinclude(X:Swithtype'at:='aX.t)endmoduleS2_to_S(X:S2):Swithtype'at=('a,unit)X.t=structtype'at=('a,unit)X.tinclude(X:S2withtype('a,'e)t:=('a,'e)X.t)endmoduleS2_to_S3(X:S2):S3withtype('a,'d,'e)t=('a,'d)X.t=structtype('a,'d,'e)t=('a,'d)X.tinclude(X:S2withtype('a,'d)t:=('a,'d)X.t)endmoduleS3_to_S2(X:S3):S2withtype('a,'d)t=('a,'d,unit)X.t=structtype('a,'d)t=('a,'d,unit)X.tinclude(X:S3withtype('a,'d,'e)t:=('a,'d,'e)X.t)end(* These functors serve only to check that the signatures for various Foo and Foo2 module
types don't drift apart over time.
*)moduleCheck_compatibility=structmoduleApplicative_infix_to_Applicative_infix2(X:Applicative_infix):Applicative_infix2withtype('a,'e)t='aX.t=structtype('a,'e)t='aX.tinclude(X:Applicative_infixwithtype'at:='aX.t)endmoduleApplicative_infix2_to_Applicative_infix(X:Applicative_infix2):Applicative_infixwithtype'at=('a,unit)X.t=structtype'at=('a,unit)X.tinclude(X:Applicative_infix2withtype('a,'e)t:=('a,'e)X.t)endmoduleApplicative_infix2_to_Applicative_infix3(X:Applicative_infix2):Applicative_infix3withtype('a,'d,'e)t=('a,'d)X.t=structtype('a,'d,'e)t=('a,'d)X.tinclude(X:Applicative_infix2withtype('a,'d)t:=('a,'d)X.t)endmoduleApplicative_infix3_to_Applicative_infix2(X:Applicative_infix3):Applicative_infix2withtype('a,'d)t=('a,'d,unit)X.t=structtype('a,'d)t=('a,'d,unit)X.tinclude(X:Applicative_infix3withtype('a,'d,'e)t:=('a,'d,'e)X.t)endmoduleLet_syntax_to_Let_syntax2(X:Let_syntax):Let_syntax2withtype('a,'e)t='aX.t=structtype('a,'e)t='aX.tinclude(X:Let_syntaxwithtype'at:='aX.t)endmoduleLet_syntax2_to_Let_syntax(X:Let_syntax2):Let_syntaxwithtype'at=('a,unit)X.t=structtype'at=('a,unit)X.tinclude(X:Let_syntax2withtype('a,'e)t:=('a,'e)X.t)endmoduleLet_syntax2_to_Let_syntax3(X:Let_syntax2):Let_syntax3withtype('a,'d,'e)t=('a,'d)X.t=structtype('a,'d,'e)t=('a,'d)X.tinclude(X:Let_syntax2withtype('a,'d)t:=('a,'d)X.t)endmoduleLet_syntax3_to_Let_syntax2(X:Let_syntax3):Let_syntax2withtype('a,'d)t=('a,'d,unit)X.t=structtype('a,'d)t=('a,'d,unit)X.tinclude(X:Let_syntax3withtype('a,'d,'e)t:=('a,'d,'e)X.t)endendmoduleMake3(X:Basic3):S3withtype('a,'d,'e)t:=('a,'d,'e)X.t=structincludeXlet(<*>)=applyletderived_mapt~f=returnf<*>tletmap=matchX.mapwith|`Define_using_apply->derived_map|`Customx->x;;let(>>|)tf=mapt~fletmap2tatb~f=map~fta<*>tbletmap3tatbtc~f=map~fta<*>tb<*>tcletallts=List.fold_rightts~init:(return[])~f:(map2~f:(funxxs->x::xs))letbothtatb=map2tatb~f:(funab->a,b)let(*>)uv=return(fun()y->y)<*>u<*>vlet(<*)uv=return(funx()->x)<*>u<*>vletall_unitts=List.foldts~init:(return())~f:(*>)moduleApplicative_infix=structlet(<*>)=(<*>)let(*>)=(*>)let(<*)=(<*)let(>>|)=(>>|)endendmoduleMake2(X:Basic2):S2withtype('a,'e)t:=('a,'e)X.t=Make3(structtype('a,'d,'e)t=('a,'d)X.tinclude(X:Basic2withtype('a,'e)t:=('a,'e)X.t)end)moduleMake(X:Basic):Swithtype'at:='aX.t=Make2(structtype('a,'e)t='aX.tinclude(X:Basicwithtype'at:='aX.t)end)moduleMake_let_syntax3(X:For_let_syntax3)(Intf:sigmoduletypeSend)(Impl:Intf.S)=structmoduleLet_syntax=structincludeXmoduleLet_syntax=structincludeXmoduleOpen_on_rhs=ImplendendendmoduleMake_let_syntax2(X:For_let_syntax2)(Intf:sigmoduletypeSend)(Impl:Intf.S)=Make_let_syntax3(structtype('a,'d,_)t=('a,'d)X.tinclude(X:For_let_syntax2withtype('a,'e)t:=('a,'e)X.t)end)(Intf)(Impl)moduleMake_let_syntax(X:For_let_syntax)(Intf:sigmoduletypeSend)(Impl:Intf.S)=Make_let_syntax2(structtype('a,_)t='aX.tinclude(X:For_let_syntaxwithtype'at:='aX.t)end)(Intf)(Impl)moduleMake3_using_map2(X:Basic3_using_map2)=Make3(structincludeXletapplytftx=map2tftx~f:(funfx->fx)letmap=matchmapwith|`Custommap->`Custommap|`Define_using_map2->`Define_using_apply;;end)moduleMake2_using_map2(X:Basic2_using_map2):S2withtype('a,'e)t:=('a,'e)X.t=Make3_using_map2(structtype('a,'d,'e)t=('a,'d)X.tinclude(X:Basic2_using_map2withtype('a,'e)t:=('a,'e)X.t)end)moduleMake_using_map2(X:Basic_using_map2):Swithtype'at:='aX.t=Make2_using_map2(structtype('a,'e)t='aX.tinclude(X:Basic_using_map2withtype'at:='aX.t)end)moduleOf_monad2(M:Monad.S2):S2withtype('a,'e)t:=('a,'e)M.t=Make2(structtype('a,'e)t=('a,'e)M.tletreturn=M.returnletapplymfmx=M.bindmf~f:(funf->M.mapmx~f)letmap=`CustomM.mapend)moduleOf_monad(M:Monad.S):Swithtype'at:='aM.t=Of_monad2(structtype('a,_)t='aM.tinclude(M:Monad.Swithtype'at:='aM.t)end)moduleCompose(F:S)(G:S):Swithtype'at='aF.tG.t=structtype'at='aF.tG.tincludeMake(structtypenonrec'at='atletreturna=G.return(F.returna)letapplytftx=G.apply(G.map~f:F.applytf)txletcustom_mapt~f=G.map~f:(F.map~f)tletmap=`Customcustom_mapend)endmodulePair(F:S)(G:S):Swithtype'at='aF.t*'aG.t=structtype'at='aF.t*'aG.tincludeMake(structtypenonrec'at='atletreturna=F.returna,G.returnaletapplytftx=F.apply(fsttf)(fsttx),G.apply(sndtf)(sndtx)letcustom_mapt~f=F.map~f(fstt),G.map~f(sndt)letmap=`Customcustom_mapend)end