1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859(* [Array0] defines array functions that are primitives or can be simply defined in terms
of [Caml.Array]. [Array0] is intended to completely express the part of [Caml.Array]
that [Base] uses -- no other file in Base other than array0.ml should use [Caml.Array].
[Array0] has few dependencies, and so is available early in Base's build order. All
Base files that need to use arrays and come before [Base.Array] in build order should
do [module Array = Array0]. This includes uses of subscript syntax ([x.(i)], [x.(i) <-
e]), which the OCaml parser desugars into calls to [Array.get] and [Array.set].
Defining [module Array = Array0] is also necessary because it prevents ocamldep from
mistakenly causing a file to depend on [Base.Array]. *)open!Import0moduleSys=Sys0letinvalid_argf=Printf.invalid_argfmoduleArray=structexternalcreate:int->'a->'aarray="caml_make_vect"externalget:'aarray->int->'a="%array_safe_get"externallength:'aarray->int="%array_length"externalset:'aarray->int->'a->unit="%array_safe_set"externalunsafe_get:'aarray->int->'a="%array_unsafe_get"externalunsafe_set:'aarray->int->'a->unit="%array_unsafe_set"endincludeArrayletmax_length=Sys.max_array_lengthletcreate~lenx=trycreatelenxwith|Invalid_argument_->invalid_argf"Array.create ~len:%d: invalid length"len();;letappend=Caml.Array.appendletblit=Caml.Array.blitletconcat=Caml.Array.concatletcopy=Caml.Array.copyletfill=Caml.Array.fillletinit=Caml.Array.initletmake_matrix=Caml.Array.make_matrixletof_list=Caml.Array.of_listletsub=Caml.Array.subletto_list=Caml.Array.to_list(* These are eta expanded in order to permute parameter order to follow Base
conventions. *)letfoldt~init~f=Caml.Array.fold_leftt~init~fletfold_rightt~f~init=Caml.Array.fold_rightt~f~initletitert~f=Caml.Array.itert~fletiterit~f=Caml.Array.iterit~fletmapt~f=Caml.Array.mapt~fletmapit~f=Caml.Array.mapit~fletstable_sortt~compare=Caml.Array.stable_sortt~cmp:compareletswaptij=lettmp=t.(i)int.(i)<-t.(j);t.(j)<-tmp;;