12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)letinvalidnameloc=Invalid_argument(Printf.sprintf"%s called from %s"nameloc)moduleOption=structletget~loc=function|Somev->v|None->raise(invalid"Lwtreslib.WithExceptions.Option.get"loc)letto_exn~none=functionSomev->v|None->raisenoneletto_exn_f~none=functionSomev->v|None->raise(none())endmoduleResult=structletget_ok~loc=function|Okv->v|Error_->raise(invalid"Lwtreslib.WithExceptions.Result.get_ok"loc)letget_error~loc=function|Errore->e|Ok_->raise(invalid"Lwtreslib.WithExceptions.Result.get_error"loc)letto_exn=functionOkv->v|Errorexc->raiseexcletto_exn_f~error=functionOkv->v|Errorb->raise(errorb)endmoduleList=structletrev_combine~locxsys=letrecauxaccxsys=match(xs,ys)with|[],[]->acc|x::xs,y::ys->aux((x,y)::acc)xsys|[],_::_|_::_,[]->raise(invalid"Lwtreslib.WithExceptions.List.rev_combine"loc)inaux[]xsysletcombine~locxsys=letrecauxaccxsys=match(xs,ys)with|[],[]->acc|x::xs,y::ys->aux((x,y)::acc)xsys|[],_::_|_::_,[]->raise(invalid"Lwtreslib.WithExceptions.List.combine"loc)inStdlib.List.rev(aux[]xsys)letmap2~locfl1l2=matchList.map2~when_different_lengths:()fl1l2with|Okv->v|Error_->raise(invalid"Lwtreslib.WithExceptions.List.map2"loc)letinit~loclf=ifl<0thenraise(invalid"Lwtreslib.WithExceptions.List.init"loc)elseStdlib.List.initlfend