123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188includeList(*
type 'a t = 'a list
= [] | (::) of 'a * 'a list
let filter_map f list =
let rec aux accu list =
match list with
| [] -> rev accu
| head :: tail ->
let accu' =
match f head with
| None -> accu
| Some head' -> head' :: accu in
aux accu' tail in
aux [] list
*)letrecpartition_map_auxleftrightflist=matchlistwith|[]->revleft,revright|hd::tl->matchfhdwith|Stdcompat__either.Leftv->partition_map_aux(v::left)rightftl|Stdcompat__either.Rightv->partition_map_auxleft(v::right)ftlletpartition_mapflist=partition_map_aux[][]flistletreccomparecmpl0l1=matchl0,l1with|[],[]->0|[],_::_->-1|_::_,[]->1|hd0::tl0,hd1::tl1->matchcmphd0hd1with|0->comparecmptl0tl1|c->cletrecequaleql0l1=matchl0,l1with|[],[]->true|[],_::_|_::_,[]->false|hd0::tl0,hd1::tl1->eqhd0hd1&&equaleqtl0tl1(*
let rec iteri_aux i f l =
match l with
| [] -> ()
| hd :: tl ->
f i hd;
iteri_aux (succ i) f tl
let iteri f l =
iteri_aux 0 f l
let rec mapi_aux i f l =
match l with
| [] -> []
| hd :: tl ->
let hd = f i hd in
hd :: mapi_aux (succ i) f tl
let mapi f l =
mapi_aux 0 f l
*)(*
let sort_uniq cmp l =
let cmp' a b = - (cmp a b) in
let rev_l = sort cmp' l in
Stdcompat__tools.uniq_rev_append cmp rev_l []
*)(*
let cons x xs =
x :: xs
*)(*
let rec compare_lengths l l' =
match l, l' with
| [], [] -> 0
| [], _ -> -1
| _, [] -> 1
| _ :: tl, _ :: tl' ->
compare_lengths tl tl'
let rec compare_length_with l n =
if n < 0 then 1
else if n = 0 then
if l = [] then 0
else 1
else
match l with
| [] -> -1
| _ :: tl -> compare_length_with tl (pred n)
let nth_opt l n =
Stdcompat__tools.option_fail (nth l) n
let find_opt p l =
try
Stdcompat__tools.option_find
(find (Stdcompat__tools.pickle_predicate_not_found p)) l
with Stdcompat__tools.Predicate_not_found ->
raise Not_found
let assoc_opt key l =
Stdcompat__tools.option_find (assoc key) l
let assq_opt key l=
Stdcompat__tools.option_find (assq key) l
*)(*
let rec init_aux i len f accu =
if i >= len then
accu
else
init_aux (succ i) len f (f i :: accu)
let rec init len f =
if len < 0 then
invalid_arg "List.init"
else if len = 0 then
[]
else
rev (init_aux 0 len f [])
*)(*
let of_seq seq =
rev (Stdcompat__seq.fold_left (fun accu x -> x :: accu) [] seq)
let rec to_seq l () =
match l with
| [] -> Stdcompat__seq.Nil
| hd :: tl -> Stdcompat__seq.Cons (hd, to_seq tl)
*)letrecfind_mapfl=matchlwith|[]->None|hd::tl->matchfhdwith|None->find_mapftl|some->someletrecconcat_rev_map_auxflaccu=matchlwith|[]->accu|hd::tl->concat_rev_map_auxftl(rev_append(fhd)accu)letconcat_mapfl=rev(concat_rev_map_auxfl[])letrecfilteri_rev_auxfliaccu=matchlwith|[]->accu|hd::tl->letaccu=iffihdthenhd::accuelseaccuinfilteri_rev_auxftl(succi)acculetfilterifl=rev(filteri_rev_auxfl0[])letfold_left_mapfaccul=letaccu,rev=fold_left(fun(accu,rev)item->letaccu,x=faccuitemin(accu,x::rev))(accu,[])linaccu,List.revrev