12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576typemsg=[`Msgofstring](** The [result] type and a bind operator. This module is meant to be opened. *)moduleResultMonad=structletmap_errorf=functionOk_asok->ok|Errore->Error(fe)letof_option~error=functionSomex->Okx|None->Errorerrorlet(>>=)=Result.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=functionOkx->Somex|Error_->Nonelet(>>=)=Option.bindendmoduleList=Odoc_listmoduleTree=TreemoduleForest=Tree.ForestmoduleJson=JsonmoduleIo_utils=struct(** [with_open_*] are resource safe wrappers around opening and closing
channels. They are equivalent to the same functions in OCaml 4.14's
[In_channel] and [Out_channel]. *)let_with_resourceres~closef=Fun.protect~finally:(fun()->closeres)(fun()->fres)letwith_open_infnamef=_with_resource(open_infname)~close:close_in_noerrfletwith_open_in_binfnamef=_with_resource(open_in_binfname)~close:close_in_noerrf(** Read a file line-by-line by folding [f]. *)letfold_linesfnamefacc=_with_resource(open_infname)~close:close_in_noerr(funic->letrecloopacc=matchinput_lineicwith|exceptionEnd_of_file->acc|line->loop(flineacc)inloopacc)(** Read a file as a list of lines. *)letread_linesfname=List.rev(fold_linesfname(funlineacc->line::acc)[])letwith_open_outfnamef=_with_resource(open_outfname)~close:close_out_noerrfletwith_open_out_binfnamef=_with_resource(open_out_binfname)~close:close_out_noerrf(** Like [with_open_out] but operate on a [Format] buffer. *)letwith_formatter_outfnamef=with_open_outfname(funoc->f(Format.formatter_of_out_channeloc))(** Shortcuts for composing [with_open_*] functions and [Marshal]. *)letmarshalfnamev=with_open_out_binfname(funoc->Marshal.to_channelocv[])letunmarshalfname=with_open_in_binfnameMarshal.from_channelendmoduleInt=structincludeIntletmaxxy:t=ifx>=ythenxelseyendincludeAstring