123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340(**************************************************************************)(* *)(* OCaml *)(* *)(* Simon Cruanes *)(* *)(* Copyright 2017 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(** Monadic traversors over {!Stdlib.Seq}.
This [Make] functor produces functions to traverse {!Stdlib.Seq}
sequences, when the function provided by the user is within a monad.
The [Make] functor does not export a new type: it only exports
traversors for the existing type exported by the Stdlib. If you need tighter
integration between your monad and the sequence, checkout
{!Seqes.Monadic}.
The buld of the documentation is located in the {!Seqes.Sigs1} module.
Familiarity with the {!Stdlib.Seq} module is also assumed.
*)moduleMake1(Mon:Sigs1.MONAD1):Sigs1.SEQMON1TRAVERSORSwithtype'amon:='aMon.twithtype'acallermon:='aMon.twithtype'at:='aStdlib.Seq.t=structletreturn=Mon.returnlet(let*)=Mon.bindletrecfold_leftfaccseq=letn=seq()inmatchnwith|Stdlib.Seq.Nil->returnacc|Cons(x,next)->let*acc=faccxinfold_leftfaccnextletreciterfseq=letn=seq()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(x,next)->let*()=fxiniterfnextletreciteri_auxfixs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(x,xs)->let*()=fixiniteri_auxf(i+1)xslet[@inline]iterifxs=iteri_auxf0xsletrecfold_lefti_auxfaccuixs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnaccu|Cons(x,xs)->let*accu=faccuixinfold_lefti_auxfaccu(i+1)xslet[@inline]fold_leftifaccuxs=fold_lefti_auxfaccu0xsletrecfor_allpxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returntrue|Cons(x,xs)->let*b=pxinifbthenfor_allpxselsereturnfalseletrecexistspxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnfalse|Cons(x,xs)->let*b=pxinifbthenreturntrueelseexistspxsletrecfindpxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnNone|Cons(x,xs)->let*b=pxinifbthenreturn(Somex)elsefindpxsletrecfind_mapfxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnNone|Cons(x,xs)->let*o=fxinmatchowith|None->find_mapfxs|Some_asresult->returnresultletreciter2fxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(y,ys)->let*()=fxyiniter2fxsysletrecfold_left2faccuxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnaccu|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->returnaccu|Cons(y,ys)->let*accu=faccuxyinfold_left2faccuxsysletrecfor_all2fxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returntrue|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->returntrue|Cons(y,ys)->let*b=fxyinifbthenfor_all2fxsyselsereturnfalseletrecexists2fxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnfalse|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->returnfalse|Cons(y,ys)->let*b=fxyinifbthenreturntrueelseexists2fxsysendmoduleMake2(Mon:Sigs2.MONAD2):Sigs2.SEQMON2TRAVERSORSwithtype('a,'e)mon:=('a,'e)Mon.twithtype('a,'e)callermon:=('a,'e)Mon.twithtype('a,'e)t:='aStdlib.Seq.t=structletreturn=Mon.returnlet(let*)=Mon.bindletrecfold_leftfaccseq=letn=seq()inmatchnwith|Stdlib.Seq.Nil->returnacc|Cons(x,next)->let*acc=faccxinfold_leftfaccnextletreciterfseq=letn=seq()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(x,next)->let*()=fxiniterfnextletreciteri_auxfixs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(x,xs)->let*()=fixiniteri_auxf(i+1)xslet[@inline]iterifxs=iteri_auxf0xsletrecfold_lefti_auxfaccuixs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnaccu|Cons(x,xs)->let*accu=faccuixinfold_lefti_auxfaccu(i+1)xslet[@inline]fold_leftifaccuxs=fold_lefti_auxfaccu0xsletrecfor_allpxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returntrue|Cons(x,xs)->let*b=pxinifbthenfor_allpxselsereturnfalseletrecexistspxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnfalse|Cons(x,xs)->let*b=pxinifbthenreturntrueelseexistspxsletrecfindpxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnNone|Cons(x,xs)->let*b=pxinifbthenreturn(Somex)elsefindpxsletrecfind_mapfxs=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnNone|Cons(x,xs)->let*o=fxinmatchowith|None->find_mapfxs|Some_asresult->returnresultletreciter2fxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->return()|Cons(y,ys)->let*()=fxyiniter2fxsysletrecfold_left2faccuxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnaccu|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->returnaccu|Cons(y,ys)->let*accu=faccuxyinfold_left2faccuxsysletrecfor_all2fxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returntrue|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->returntrue|Cons(y,ys)->let*b=fxyinifbthenfor_all2fxsyselsereturnfalseletrecexists2fxsys=letn=xs()inmatchnwith|Stdlib.Seq.Nil->returnfalse|Cons(x,xs)->letn=ys()inmatchnwith|Stdlib.Seq.Nil->returnfalse|Cons(y,ys)->let*b=fxyinifbthenreturntrueelseexists2fxsysend