Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file list0.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123(* [List0] defines list functions that are primitives or can be simply defined in terms of
[Stdlib.List]. [List0] is intended to completely express the part of [Stdlib.List] that
[Base] uses -- no other file in Base other than list0.ml should use [Stdlib.List].
[List0] has few dependencies, and so is available early in Base's build order. All
Base files that need to use lists and come before [Base.List] in build order should do
[module List = List0]. Defining [module List = List0] is also necessary because it
prevents ocamldep from mistakenly causing a file to depend on [Base.List]. *)open!Import0lethd_exn=Stdlib.List.hdletrev_append=Stdlib.List.rev_appendlettl_exn=Stdlib.List.tlletunzip=Stdlib.List.split(* Some of these are eta expanded in order to permute parameter order to follow Base
conventions. *)letlength=letreclength_auxlen=function|[]->len|_::l->length_aux(len+1)linfunl->length_aux0l;;letrecexistst~f=matchtwith|[]->false|x::xs->iffxthentrueelseexistsxs~f;;letrecexists2_okl1l2~(f:_->_->_)=matchl1,l2with|[],[]->false|a1::l1,a2::l2->fa1a2||exists2_okl1l2~f|_,_->invalid_arg"List.exists2";;letrecfoldt~init~(f:_->_->_)=matchtwith|[]->init|a::l->foldl~init:(finita)~f;;letrecfold2_okl1l2~init~(f:_->_->_->_)=matchl1,l2with|[],[]->init|a1::l1,a2::l2->fold2_okl1l2~f~init:(finita1a2)|_,_->invalid_arg"List.fold_left2";;letfor_allt~f=not(existst~f:(funx->not(fx)))letrecfor_all2_okl1l2~(f:_->_->_)=matchl1,l2with|[],[]->true|a1::l1,a2::l2->fa1a2&&for_all2_okl1l2~f|_,_->invalid_arg"List.for_all2";;letrecitert~(f:_->_)=matchtwith|[]->()|a::l->fa;iterl~f;;letreciter2_okl1l2~(f:_->_->unit)=matchl1,l2with|[],[]->()|a1::l1,a2::l2->fa1a2;iter2_okl1l2~f|_,_->invalid_arg"List.iter2";;letrecnontail_mapt~f=matchtwith|[]->[]|x::xs->lety=fxiny::nontail_mapxs~f;;letnontail_mapit~f=Stdlib.List.mapit~fletpartitiont~f=Stdlib.List.partitiont~fletrev_map=letrecrmap_ffaccu=function|[]->accu|a::l->rmap_ff(fa::accu)linfunl~f->rmap_ff[]l;;letrev_map2_ok=letrecrmap2_ffaccul1l2=matchl1,l2with|[],[]->accu|a1::l1,a2::l2->rmap2_ff(fa1a2::accu)l1l2|_,_->invalid_arg"List.rev_map2"infunl1l2~(f:_->_->_)->rmap2_ff[]l1l2;;letrev=function|([]|[_])asres->res|x::y::rest->rev_appendrest[y;x];;letfold_rightl~(f:_->_->_)~init=matchlwith|[]->init(* avoid the allocation of [~f] below *)|_->fold~f:(funab->fba)~init(revl)[@nontail];;letfold_right2_okl1l2~(f:_->_->_->_)~init=matchl1,l2with|[],[]->init(* avoid the allocation of [~f] below *)|_,_->fold2_ok~f:(funabc->fbca)~init(revl1)(revl2)[@nontail];;