123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Basic Functions} *)letopaque_identityx=x(* import standard implementations, if any *)includeSysincludeCCShims_.Stdlib[@@@ifge4.8]includeFun[@@@else_]externalid:'a->'a="%identity"let[@inline]flipfxy=fyxlet[@inline]constx_=xlet[@inline]negatefx=not(fx)let[@inline]protect~finally f=tryletx=f()infinally();xwithe->finally();raisee[@@@endif]letcomposefgx=g(fx)letcompose_binopfgxy=g(fx)(fy)letcurryfxy=f(x,y)letuncurryf(x,y)=fxylettapfx=ignore(fx);xletlexicographicf1f2xy=letc=f1xyinifc<>0thencelsef2xyletfinally~h~f=tryletx=f()inignore(h());xwithe->ignore(h());raiseeletfinally1~hfx=tryletres=fxinignore(h());reswithe->ignore(h());raiseeletfinally2~hfxy=tryletres=fxyinignore(h());reswithe->ignore(h());raiseeletreciteratenfx=ifn<0theninvalid_arg"CCFun.iterate"elseifn=0thenxelseiterate(n-1)f(fx)moduleInfix=struct(* default implem for some operators *)let(|>)=CCShims_.Stdlib.(|>)let(@@)=CCShims_.Stdlib.(@@)let(%>)=composelet[@inline](%)fgx=f(gx)[@@@ifge4.8]let(let@)=(@@)[@@@endif]endincludeInfixmoduleMonad(X:sigtypetend)=structtype'at=X.t->'alet[@inline]returnx_=xlet[@inline](>|=)fgx=g(fx)let[@inline](>>=)fgx=g(fx)xend[@@inline]