123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110(******************************************************************************)(* *)(* Sek *)(* *)(* Arthur Charguéraud, Émilie Guermeur and François Pottier *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under the *)(* terms of the GNU Lesser General Public License as published by the Free *)(* Software Foundation, either version 3 of the License, or (at your *)(* option) any later version, as described in the file LICENSE. *)(* *)(******************************************************************************)let[@inline]try_finallyactionhandler=matchaction()with|y->handler();y|exceptione->handler();raiseetype('a,'c)iter=('a->unit)->'c->unittype('a,'c)iteri=(int->'a->unit)->'c->unittype('a,'b,'c)fold_left=('b->'a->'b)->'b->'c->'btype('a,'b,'c)fold_right=('a->'b->'b)->'c->'b->'blet[@inline]fold_leftiter_leftfseedc=letaccu=refseedinletfx=accu:=f!accuxiniter_leftfc;!acculet[@inline]fold_rightiter_rightfcseed=letaccu=refseedinletfx=accu:=fx!accuiniter_rightfc;!acculet[@inline]iteri_leftiter_leftfs=leti=ref(-1)inletfa=(i:=!i+1;f!ia)initer_leftfslet[@inline]iteri_rightlengthiter_rightfs=leti=ref(lengths)inletfa=(i:=!i-1;f!ia)initer_rightfstype('a1,'a2,'c1,'c2)iter2=('a1->'a2->unit)->'c1->'c2->unittype('a1,'a2,'b,'c1,'c2)fold_left2=('b->'a1->'a2->'b)->'b->'c1->'c2->'btype('a1,'a2,'b,'c1,'c2)fold_right2=('a1->'a2->'b->'b)->'c1->'c2->'b->'blet[@inline]fold_left2iter_left2fseedc1c2=letaccu=refseedinletfx1x2=accu:=f!accux1x2initer_left2fc1c2;!acculet[@inline]fold_right2iter_right2fc1c2seed=letaccu=refseedinletfx1x2=accu:=fx1x2!accuiniter_right2fc1c2;!accutype('a,'c)to_list='c->'alistlet[@inline]to_listfold_rightc=fold_right(funxxs->x::xs)c[]let[@inline]to_listiter_rightc=to_list(fold_rightiter_right)ctype'aiterator=unit->'aexceptionExhaustedlet[@inline]iterator_of_seq(xs:'aSeq.t)=letcurrent=refxsinfun()->match!current()with|Seq.Nil->raiseExhausted|Seq.Cons(x,xs)->current:=xs;xlet[@inline]iterator_of_list(xs:'alist)=letcurrent=refxsinfun()->match!currentwith|[]->raiseExhausted|x::xs->current:=xs;x