12345678910111213141516171819202122232425262728293031323334353637383940414243444546(* This file is part of asak.
*
* Copyright (C) 2019 IRIF / OCaml Software Foundation.
*
* asak is distributed under the terms of the MIT license. See the
* included LICENSE file for details. *)leteitherfg=function|Okx->fx|Errorx->gxmoduletypeT=sigtypeeendmoduleMake(T:T):sigtype'atvalfail:T.e->'atvalret:'a->'atvalmap:('a->'b)->'at->'btval(>>=):'at->('a->'bt)->'btvalrun:'at->('a,T.e)resultvalto_err:('a,T.e)result->'atvalerr_of_option:T.e->'aoption->'atend=structtype'at=('a,T.e)resultletfaile=Erroreletretx=Okxletmapf=either(funx->ret(fx))faillet(>>=)xf=eitherffailxletrunx=xletto_errx=xleterr_of_optione=function|None->faile|Somex->retxendmoduleErrS=Make(structtypee=stringend)letfilter_rev_mapfxs=List.fold_left(funaccx->either(funx->x::acc)(fun_->acc)@@fx)[]xs