123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475(******************************************************************************)(* *)(* Fix *)(* *)(* François Pottier, Inria Paris *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under the *)(* terms of the GNU Library General Public License version 2, with a *)(* special exception on linking, as described in the file LICENSE. *)(* *)(******************************************************************************)type'aenum=('a->unit)->unitlet[@inline]enum(xs:('a->unit)->unit):'aenum=xslet[@inline]foreach(xs:'aenum):('a->unit)->unit=xslet[@inline]empty=fun_yield->()let[@inline]cons(x:'a)(xs:'aenum):'aenum=funyield->yieldx;foreachxsyieldlet[@inline]singletonx=funyield->yieldxletlist(xs:'alist):'aenum=funyield->List.iteryieldxsletarray(xs:'aarray):'aenum=funyield->Array.iteryieldxsletenum_to_reversed_list(iter:'aenum):'alist=letxs=ref[]initer(funx->xs:=x::!xs);!xsletenum_to_list(iter:'aenum):'alist=List.rev(enum_to_reversed_listiter)(* [enum_to_array] and [enum_to_reversed_array] use one or two intermediate
lists. This presents the drawback of allocating intermediate data
structures, and the advantage of consuming the enumeration only once (which
could be important, if the enumeration is not persistent). *)letenum_to_reversed_array(iter:'aenum):'aarray=Array.of_list(enum_to_reversed_listiter)letenum_to_array(iter:'aenum):'aarray=Array.of_list(enum_to_listiter)letlength(iter:'aenum):int=letc=ref0initer(fun_x->incrc);!cletfilter(f:'a->bool)(iter:'aenum):'aenum=funyield->iter@@funx->iffxthenyieldxletmap(f:'a->'b)(iter:'aenum):'benum=funyield->iter@@funx->yield(fx)