123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)(** [S] is the signature for a Lwt, result and Lwt-result combined monad. It is
similar to {!Bare_sigs.Monad} with the addition of traces. Specifically:
- The type ['error trace] is meant to be substituted by a type provided by a
[Trace] module ([with type 'error trace := 'error Trace.trace]).
- The functions {!Traced_result_syntax.fail} and
{!Traced_lwt_result_syntax.fail} wrap the provided error in a trace,
- [{join,all,both}] return ['error trace] rather than ['error list],
- The binding operators {!Traced_result_syntax.( and* )} and
{!Traced_lwt_result_syntax.( and* )} are available.
*)moduletypeS=sig(** Import the non-traced modules as-is *)includeBare_sigs.Monad.S(** ['error trace] is intended to be substituted by a type provided by a
[Trace] module ([with type 'error trace := 'error Trace.trace]) *)type'errortrace(** {2 The traced Result monad: for successes and traced failures}
The [Traced_result_syntax] module is similar to the [Result_syntax] module
with the following differences:
- [fail] wraps the error in a trace,
- [and*] and [and+] are provided
See {!Result_syntax}. *)moduleTraced_result_syntax:sigvalreturn:'a->('a,'error)resultvalreturn_unit:(unit,'error)resultvalreturn_none:('aoption,'error)resultvalreturn_some:'a->('aoption,'error)resultvalreturn_nil:('alist,'error)resultvalreturn_true:(bool,'error)resultvalreturn_false:(bool,'error)result(** [fail e] is [(Error (Trace.make e))] where [Trace] is the
{!Traced_sigs.Trace} module that provides the trace type and functions. *)valfail:'error->('a,'errortrace)resultval(let*):('a,'e)result->('a->('b,'e)result)->('b,'e)resultval(and*):('a,'etrace)result->('b,'etrace)result->('a*'b,'etrace)resultval(let+):('a,'e)result->('a->'b)->('b,'e)resultval(and+):('a,'etrace)result->('b,'etrace)result->('a*'b,'etrace)resultvaljoin:(unit,'errortrace)resultlist->(unit,'errortrace)resultvalall:('a,'errortrace)resultlist->('alist,'errortrace)resultvalboth:('a,'errortrace)result->('b,'errortrace)result->('a*'b,'errortrace)resultend(** {2 The Lwt traced Result monad: for concurrent successes and traced failures}
The [Lwt_traced_result_syntax] module is similar to the
[Lwt_result_syntax] module with the following difference:
- [fail] wraps the error in a trace,
- [and*] and [and+] are provided.
See {!Lwt_result_syntax}. *)moduleLwt_traced_result_syntax:sigvalreturn:'a->('a,'error)resultLwt.tvalreturn_unit:(unit,'error)resultLwt.tvalreturn_none:('aoption,'error)resultLwt.tvalreturn_some:'a->('aoption,'error)resultLwt.tvalreturn_nil:('alist,'error)resultLwt.tvalreturn_true:(bool,'error)resultLwt.tvalreturn_false:(bool,'error)resultLwt.t(** [fail e] is [Lwt.return (Error (Trace.make e))] where [Trace] is the
{!Traced_sigs.Trace} module that provides the trace type and functions. *)valfail:'error->('a,'errortrace)resultLwt.tval(let*):('a,'e)resultLwt.t->('a->('b,'e)resultLwt.t)->('b,'e)resultLwt.tval(and*):('a,'etrace)resultLwt.t->('b,'etrace)resultLwt.t->('a*'b,'etrace)resultLwt.tval(let+):('a,'e)resultLwt.t->('a->'b)->('b,'e)resultLwt.tval(and+):('a,'etrace)resultLwt.t->('b,'etrace)resultLwt.t->('a*'b,'etrace)resultLwt.tval(let*!):'aLwt.t->('a->'bLwt.t)->'bLwt.tval(let*?):('a,'e)result->('a->('b,'e)resultLwt.t)->('b,'e)resultLwt.tvaljoin:(unit,'errortrace)resultLwt.tlist->(unit,'errortrace)resultLwt.tvalall:('a,'errortrace)resultLwt.tlist->('alist,'errortrace)resultLwt.tvalboth:('a,'errortrace)resultLwt.t->('b,'errortrace)resultLwt.t->('a*'b,'errortrace)resultLwt.tendend