123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180[@@@warning"@A"]letcount?(step:int=1)(start:int):int Seq.t=letrecaux(i:int):intSeq.t=fun()->Seq.Cons(i,aux(i+step))inauxstartlet cycle(typea)(p:alist):aSeq.t=letrecaux(l:alist):aSeq.t=fun()->matchl,pwith|h::t,_->Seq.Cons(h,auxt)|[],_::_->auxp()|[],[]->Seq.Nilinauxpletrepeat(typea)?(n:intoption)(elem:a):aSeq.t=matchnwith|None->letrecaux():aSeq.node=Seq.Cons(elem,aux)inaux|Some n->letrecaux(n:int):aSeq.t=fun()->matchnwith|0->Seq.Nil|n->Seq.Cons(elem,aux(n-1))inaux nletaccumulate(typea)(f:a->a->a)(l:aSeq.t):aSeq.t=matchl()with|Seq.Nil->Seq.empty|Seq.Cons(h,t)->letrecaux(acc:a)(l:aSeq.t):aSeq.t=fun()->matchl()with|Seq.Nil->Seq.Cons(acc,Seq.empty)|Seq.Cons(h,t)->Seq.Cons(acc,aux(fhacc)t)inauxhtletaccumulate_l(typea)(f:a->a->a)(l:alist):alist=matchlwith|[]->[]|h::t->letrecaux(acc:a)(l:alist):alist =match lwith|[]->[acc]|h::t->acc::aux(fhacc)tinauxhtletchain(typea)(its:aSeq.tlist):aSeq.t=match its with|[]->Seq.empty|it::its->letrecaux(it:aSeq.t)(its:aSeq.tlist):aSeq.t=fun()->matchit()with|Seq.Cons(h,t)->Seq.Cons(h,auxtits)|Seq.Nil->matchitswith|[]->Seq.Nil|it::its->auxitits()inaux ititsletcompress(typea)(it:aSeq.t)(sel:boolSeq.t):aSeq.t=let recaux(it:aSeq.t)(sel:boolSeq.t):aSeq.t=fun()->matchit(),sel()with|Seq.Nil,_|_,Seq.Nil->Seq.Nil|Seq.Cons(h1,t1),Seq.Cons(h2,t2)->ifh2thenSeq.Cons(h1,auxt1t2)elseauxt1t2()inauxitselletdropwhile(typea)(pred:a->bool)(it:aSeq.t):aSeq.t=letrecaux(it:aSeq.t):aSeq.t=fun()->matchit()with|Seq.Nil->Seq.Nil|Seq.Cons(h,t)->ifpredhthenauxt()elset()inauxitletfilterfalse(typea)(pred:a->bool)(it:aSeq.t):aSeq.t=Seq.filter (Stdcompat.Fun.negatepred)itletislice?(start:int option)?(stop:intoption)?(step:int=1)(typea)(it:aSeq.t):aSeq.t=ifstep<=0thenraise(Exn.ValueError"Step for islice() must be a positive integer or None.");letstart=matchstartwith|None->0|Somenwhenn>=0->n|_->raise(Exn.ValueError"Indices for islice() must be None or a non negative integer.")inlet()=matchstopwith|None->()|Somenwhenn>=0->()|_->raise(Exn.ValueError"Indices for islice() must be None or a non negative integer.")inletrecforward(n:int)(it:aSeq.t):aSeq.t=matchnwith|0->it|n->matchit()with|Seq.Nil->Seq.empty|Seq.Cons(_,t)->forward(n-1)tinletstarted =forwardstartitinletrecdo_step(it:aSeq.t)(s:int)(pos:int):aSeq.t=fun()->matchstopwith|Somenwhen pos>=n->Seq.Nil|Some _|None->matchit(),swith|Seq.Nil,_->Seq.Nil|Seq.Cons(h,t),0->Seq.Cons(h,do_stept(step-1)(pos+1))|Seq.Cons(_,t),s->do_stept(s-1)(pos+1)()indo_stepstarted(step-1)startlettakewhile(typea)(pred:a->bool)(it:aSeq.t):aSeq.t=letrecaux(it:aSeq.t):aSeq.t=fun()->matchit()with|Seq.Cons(h,t)whenpredh->Seq.Cons(h,auxt)|Seq.Cons_|Seq.Nil->Seq.Nilinauxitletzip_longest(typeab)(a:aSeq.t)(b:bSeq.t):(aoption*boption)Seq.t=letrecaux(a:aSeq.t)(b:bSeq.t):(aoption*boption)Seq.t=fun()->matcha(),b()with|Seq.Nil,Seq.Nil->Seq.Nil|Seq.Cons(h,t),Seq.Nil->Seq.Cons((Someh,None),auxtb)|Seq.Nil,Seq.Cons(h,t)->Seq.Cons((None,Someh),auxat)|Seq.Cons(h1,t1),Seq.Cons(h2,t2)->Seq.Cons((Someh1,Someh2),auxt1t2)inauxabletzip_longest_default (typeab)(def_a:a)(def_b:b)(a:aSeq.t)(b:bSeq.t):(a*b)Seq.t=let recaux(a:aSeq.t)(b:bSeq.t):(a*b)Seq.t=fun()->matcha(),b()with|Seq.Nil,Seq.Nil->Seq.Nil|Seq.Cons(h,t),Seq.Nil->Seq.Cons((h,def_b),auxtb)|Seq.Nil,Seq.Cons(h,t)->Seq.Cons((def_a,h),auxat)|Seq.Cons(h1,t1),Seq.Cons(h2,t2)->Seq.Cons((h1,h2),auxt1t2)inauxabletproduct (typeab)(a:aSeq.t)(b:bSeq.t):(a*b)Seq.t=let recaux(a_:aSeq.t)(b_:bSeq.t):(a*b)Seq.t=fun()->matcha_(),b_()with|_,Seq.Nil->Seq.Nil|Seq.Nil,Seq.Cons(_,tb)->auxatb()|Seq.Cons(ha,ta),Seq.Cons(hb,_)->Seq.Cons((ha,hb),auxtab_)inauxab