123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293type('i,'o)t='i->('o,'iError.t)resultletpurex:('i,'o)t=fun_i->Okxletfailmsg:('i,'o)t=funi->Error(Error.make~context:imsg)letfail_withe:('i,'o)t=fun_i->Erroreletof_result=functionOko->pureo|Errore->fail_witheletbind(f:'a->('i,'b)t)(x:('i,'a)t):('i,'b)t=funi->matchxiwithOky->fyi|Errore->Erroreletmap(f:'a->'b)(x:('i,'a)t):('i,'b)t=funi->matchxiwithOky->Ok(fy)|Errore->Erroreletmap_err(f:'iError.t->'iError.t)(x:('i,'o)t):('i,'o)t=funi->matchxiwithOky->Oky|Errore->Error(fe)letapply(f:('i,'a->'b)t)(x:('i,'a)t):('i,'b)t=funi->matchfiwith|Okf->(matchxiwithOkx->Ok(fx)|Errore->Errore)|Errore->ErroremoduleInfix=structlet[@inline](>>=)xf=bindfxlet[@inline](>|=)xf=mapfxlet[@inline](<*>)fx=applyfxincludeShims_let_ops_.Make(structtypenonrec('i,'o)t=('i,'o)tlet(>>=)=(>>=)let(>|=)=(>|=)let[@inline]monoid_productab=map(funxy->(x,y))a<*>bend)endletfix(f:('i,'a)t->('i,'a)t):('i,'a)t=letrecp=lazy(fr)andrvalue=(Lazy.forcep)valueinrletvalue:('i,'i)t=funi->Okiletmaybe(x:('i,'a)t):('i,'aoption)t=funi->matchxiwithOkx->Ok(Somex)|Error_->OkNoneletone_of(xs:('i,'o)tlist):('i,'o)t=funi->letrecauxerrors=function|x::xs->(matchxiwithOko->Oko|Errore->aux(e::errors)xs)|[]->Error(Error.group(List.reverrors))inaux[]xsletpick:('i,('i,'o)t)tlist->('i,'o)t=fundecodersinput->letrecgoerrors=function|decoder::rest->(matchdecoderinputwith|Okdec->(* use [dec] and drop errors *)(matchdecinputwithOk_asx->x|Errore->Errore)|Errorerror->go(error::errors)rest)|[]->Error(Error.grouperrors)ingo[]decodersletof_to_opt(to_opt:'i->'ooption)fail:('i,'o)t=funi->matchto_optiwithSomeo->Oko|None->faililetdecode_subvdec=of_result(decv)