12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273(**************************************************************************)(* *)(* 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. *)(* *)(**************************************************************************)(* Module [Seq]: functional iterators *)type+'anode=|Nil|Consof'a*'atand'at=unit->'anodeletempty()=Nilletreturnx()=Cons(x,empty)letrecmapfseq()=matchseq()with|Nil->Nil|Cons(x,next)->Cons(fx,mapfnext)letrecfilter_mapfseq()=matchseq()with|Nil->Nil|Cons(x,next)->matchfxwith|None->filter_mapfnext()|Somey->Cons(y,filter_mapfnext)letrecfilterfseq()=matchseq()with|Nil->Nil|Cons(x,next)->iffxthenCons(x,filterfnext)elsefilterfnext()letrecflat_mapfseq()=matchseq()with|Nil->Nil|Cons(x,next)->flat_map_appf(fx)next()(* this is [append seq (flat_map f tail)] *)andflat_map_appfseqtail()=matchseq()with|Nil->flat_mapftail()|Cons(x,next)->Cons(x,flat_map_appfnexttail)letfold_leftfaccseq=letrecauxfaccseq=matchseq()with|Nil->acc|Cons(x,next)->letacc=faccxinauxfaccnextinauxfaccseqletiterfseq=letrecauxseq=matchseq()with|Nil->()|Cons(x,next)->fx;auxnextinauxseq