12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455(** The [result] type and a bind operator. This module is meant to be opened. *)moduleResultMonad=struct(** Re-export for compat *)type('a,'b)result=('a,'b)Result.result=Okof'a|Errorof'bletmap_errorf=functionOk_asok->ok|Errore->Error(fe)letof_option~error=functionSomex->Okx|None->Errorerrorletbindmf=matchmwithOkx->fx|Error_ase->elet(>>=)=bindend(** A bind operator for the [option] type. This module is meant to be opened. *)moduleOptionMonad=struct(* The error case become [None], the error value is ignored. *)letof_result=functionResult.Okx->Somex|Error_->Noneletreturnx=Somexletbindmf=matchmwithSomex->fx|None->Nonelet(>>=)=bindendmoduleEitherMonad=structtype('a,'b)t=Leftof'a|Rightof'bletreturnx=Rightxletreturn_leftx=Leftxletbindmf=matchmwithRightx->fx|Lefty->Leftyletbind_leftmf=matchmwithLeftx->fx|Righty->Rightylet(>>=)=bindletof_option~left=functionSomex->Rightx|None->Leftleftletof_result=functionResult.Okx->Rightx|Errory->Leftyendletrecconcat_mapaccf=function|hd::tl->concat_map(List.rev_append(fhd)acc)ftl|[]->List.revaccletrecfilter_mapaccf=function|hd::tl->letacc=matchfhdwithSomex->x::acc|None->accinfilter_mapaccftl|[]->List.revaccletoption_value~defaultv=matchvwithNone->default|Somev->v