123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduleMake(Monad:Traced_sigs.Monad.S):Traced_sigs.List.Swithtype'errortrace:='errorMonad.trace=structopenMonadincludeBare_structs.Listletinit_ep~when_negative_lengthlf=letopenLwt_traced_result_syntaxinletrecauxacci=ifi>=lthenall(revacc)else(aux[@ocaml.tailcall])(Lwt.applyfi::acc)(i+1)inifl<0thenfailwhen_negative_lengthelseifl=0thennil_eselseaux[]0letiter_epfl=Lwt_traced_result_syntax.join(rev_map(Lwt.applyf)l)letlwt_apply2fxy=tryfxywithexn->Lwt.failexnletiteri_epfl=Lwt_traced_result_syntax.join(mapi(lwt_apply2f)l)letrev_map_epfl=Lwt_traced_result_syntax.all@@rev_map(Lwt.applyf)lletmap_epfl=rev_map_epfl|>Lwt_result.maprevletrev_mapi_epfl=Lwt_traced_result_syntax.all@@rev_mapiflletmapi_epfl=rev_mapi_epfl|>Lwt_result.maprevletfilter_epfl=rev_map_ep(funx->letopenLwt_traced_result_syntaxinlet*b=fxinifbthenreturn_somexelsereturn_none)l|>Lwt_result.maprev_filter_someletfilteri_epfl=rev_mapi_ep(funix->letopenLwt_traced_result_syntaxinlet*b=fixinifbthenreturn_somexelsereturn_none)l|>Lwt_result.maprev_filter_someletfilter_map_epfl=rev_map_epfl|>Lwt_result.maprev_filter_someletconcat_map_epfxs=letopenLwt_traced_result_syntaxinlet+r=all(mapfxs)inflattenrletfor_all_epfl=rev_map_epfl|>Lwt_result.map(for_allFun.id)letexists_epfl=rev_map_epfl|>Lwt_result.map(existsFun.id)letpartition_epfl=letopenLwt_traced_result_syntaxinlet*bxs=rev_map_ep(funx->let*b=fxinreturn(b,x))linreturn@@fold_left(fun(trues,falses)(b,x)->ifbthen(x::trues,falses)else(trues,x::falses))([],[])bxsletpartition_map_epfl=letopenLwt_result_syntaxinlet*es=rev_map_epflinletr=rev_partition_eitheresinreturnrend