A monad is an abstraction of the concept of sequencing of computations. A value of type 'a monad represents a computation that returns a value of type 'a.
return v returns the (trivial) computation that returns v.
try_with f catches exceptions thrown by
f and returns them in the Result.t as an
try_with_join is like
try_with, except that
f can throw exceptions or
return an Error directly, without ending up with a nested error; it is equivalent to
Result.join (try_with f).
ok_exn t throws an exception if
t is an
Error, and otherwise returns the
contents of the
of_exn exn is
Error (Error.of_exn exn).
error is a wrapper around
error ?strict message a sexp_of_a = Error (Error.create ?strict message a sexp_of_a)
sexp_of_a a is lazily computed, when the info is converted
to a sexp. So, if
a is mutated in the time between the call to
create and the
sexp conversion, those mutations will be reflected in the sexp. Use
sexp_of_a a to be computed immediately.
error_string message is
Error (Error.of_string message)
errorf format arg1 arg2 ... is
Error (sprintf format arg1 arg2 ...). Note that it
calculates the string eagerly, so when performance matters you may want to use
For marking a given value as unimplemented. Typically combined with conditional compilation, where on some platforms the function is defined normally, and on some platforms it is defined as unimplemented. The supplied string should be the name of the function that is unimplemented.
combine_errors ts returns
Ok if every element in
Ok, else it returns
Error with all the errors in
ts. More precisely:
Ok a1; ...; Ok an = Ok
a1; ...; an
...; Error e1; ...; Error en; ...
| = Error (Error.of_list
e1; ...; en)