Module Base.Or_errorSource
Type for tracking errors in an Error.t. This is a specialization of the Result type, where the Error constructor carries an Error.t.
A common idiom is to wrap a function that is not implemented on all platforms, e.g.,
val do_something_linux_specific : (unit -> unit) Or_error.tval compare__bits64 :
('a -> 'a -> int) ->
('a, Base.Error.t) Base.Result.t__bits64 ->
('a, Base.Error.t) Base.Result.t__bits64 ->
int @@ portableval compare__bits64__local :
('a @ local -> 'a @ local -> int) ->
('a, Base.Error.t) Base.Result.t__bits64 @ local ->
('a, Base.Error.t) Base.Result.t__bits64 @ local ->
int @@ portableval compare__bits32 :
('a -> 'a -> int) ->
('a, Base.Error.t) Base.Result.t__bits32 ->
('a, Base.Error.t) Base.Result.t__bits32 ->
int @@ portableval compare__bits32__local :
('a @ local -> 'a @ local -> int) ->
('a, Base.Error.t) Base.Result.t__bits32 @ local ->
('a, Base.Error.t) Base.Result.t__bits32 @ local ->
int @@ portableval compare__word :
('a -> 'a -> int) ->
('a, Base.Error.t) Base.Result.t__word ->
('a, Base.Error.t) Base.Result.t__word ->
int @@ portableval compare__word__local :
('a @ local -> 'a @ local -> int) ->
('a, Base.Error.t) Base.Result.t__word @ local ->
('a, Base.Error.t) Base.Result.t__word @ local ->
int @@ portableval compare__float64 :
('a -> 'a -> int) ->
('a, Base.Error.t) Base.Result.t__float64 ->
('a, Base.Error.t) Base.Result.t__float64 ->
int @@ portableval compare__float64__local :
('a @ local -> 'a @ local -> int) ->
('a, Base.Error.t) Base.Result.t__float64 @ local ->
('a, Base.Error.t) Base.Result.t__float64 @ local ->
int @@ portableval compare__float32 :
('a -> 'a -> int) ->
('a, Base.Error.t) Base.Result.t__float32 ->
('a, Base.Error.t) Base.Result.t__float32 ->
int @@ portableval compare__float32__local :
('a @ local -> 'a @ local -> int) ->
('a, Base.Error.t) Base.Result.t__float32 @ local ->
('a, Base.Error.t) Base.Result.t__float32 @ local ->
int @@ portableval equal__bits64 :
('a -> 'a -> bool) ->
('a, Base.Error.t) Base.Result.t__bits64 ->
('a, Base.Error.t) Base.Result.t__bits64 ->
bool @@ portableval equal__bits64__local :
('a @ local -> 'a @ local -> bool) ->
('a, Base.Error.t) Base.Result.t__bits64 @ local ->
('a, Base.Error.t) Base.Result.t__bits64 @ local ->
bool @@ portableval equal__bits32 :
('a -> 'a -> bool) ->
('a, Base.Error.t) Base.Result.t__bits32 ->
('a, Base.Error.t) Base.Result.t__bits32 ->
bool @@ portableval equal__bits32__local :
('a @ local -> 'a @ local -> bool) ->
('a, Base.Error.t) Base.Result.t__bits32 @ local ->
('a, Base.Error.t) Base.Result.t__bits32 @ local ->
bool @@ portableval equal__word :
('a -> 'a -> bool) ->
('a, Base.Error.t) Base.Result.t__word ->
('a, Base.Error.t) Base.Result.t__word ->
bool @@ portableval equal__word__local :
('a @ local -> 'a @ local -> bool) ->
('a, Base.Error.t) Base.Result.t__word @ local ->
('a, Base.Error.t) Base.Result.t__word @ local ->
bool @@ portableval equal__float64 :
('a -> 'a -> bool) ->
('a, Base.Error.t) Base.Result.t__float64 ->
('a, Base.Error.t) Base.Result.t__float64 ->
bool @@ portableval equal__float64__local :
('a @ local -> 'a @ local -> bool) ->
('a, Base.Error.t) Base.Result.t__float64 @ local ->
('a, Base.Error.t) Base.Result.t__float64 @ local ->
bool @@ portableval equal__float32 :
('a -> 'a -> bool) ->
('a, Base.Error.t) Base.Result.t__float32 ->
('a, Base.Error.t) Base.Result.t__float32 ->
bool @@ portableval equal__float32__local :
('a @ local -> 'a @ local -> bool) ->
('a, Base.Error.t) Base.Result.t__float32 @ local ->
('a, Base.Error.t) Base.Result.t__float32 @ local ->
bool @@ portableval globalize__bits64 :
('a @ local -> 'a) ->
('a, Base.Error.t) Base.Result.t__bits64 @ local ->
('a, Base.Error.t) Base.Result.t__bits64 @@ portableval globalize__bits32 :
('a @ local -> 'a) ->
('a, Base.Error.t) Base.Result.t__bits32 @ local ->
('a, Base.Error.t) Base.Result.t__bits32 @@ portableval globalize__word :
('a @ local -> 'a) ->
('a, Base.Error.t) Base.Result.t__word @ local ->
('a, Base.Error.t) Base.Result.t__word @@ portableval globalize__float64 :
('a @ local -> 'a) ->
('a, Base.Error.t) Base.Result.t__float64 @ local ->
('a, Base.Error.t) Base.Result.t__float64 @@ portableval globalize__float32 :
('a @ local -> 'a) ->
('a, Base.Error.t) Base.Result.t__float32 @ local ->
('a, Base.Error.t) Base.Result.t__float32 @@ portableval sexp_of_t__bits64 :
('a -> Sexplib0.Sexp.t) ->
('a, Base.Error.t) Base.Result.t__bits64 ->
Sexplib0.Sexp.t @@ portableval sexp_of_t__bits32 :
('a -> Sexplib0.Sexp.t) ->
('a, Base.Error.t) Base.Result.t__bits32 ->
Sexplib0.Sexp.t @@ portableval sexp_of_t__word :
('a -> Sexplib0.Sexp.t) ->
('a, Base.Error.t) Base.Result.t__word ->
Sexplib0.Sexp.t @@ portableval sexp_of_t__float64 :
('a -> Sexplib0.Sexp.t) ->
('a, Base.Error.t) Base.Result.t__float64 ->
Sexplib0.Sexp.t @@ portableval sexp_of_t__float32 :
('a -> Sexplib0.Sexp.t) ->
('a, Base.Error.t) Base.Result.t__float32 ->
Sexplib0.Sexp.t @@ portableval t_of_sexp__bits64 :
(Sexplib0.Sexp.t -> 'a) ->
Sexplib0.Sexp.t ->
('a, Base.Error.t) Base.Result.t__bits64 @@ portableval t_of_sexp__bits32 :
(Sexplib0.Sexp.t -> 'a) ->
Sexplib0.Sexp.t ->
('a, Base.Error.t) Base.Result.t__bits32 @@ portableval t_of_sexp__word :
(Sexplib0.Sexp.t -> 'a) ->
Sexplib0.Sexp.t ->
('a, Base.Error.t) Base.Result.t__word @@ portableval t_of_sexp__float64 :
(Sexplib0.Sexp.t -> 'a) ->
Sexplib0.Sexp.t ->
('a, Base.Error.t) Base.Result.t__float64 @@ portableval t_of_sexp__float32 :
(Sexplib0.Sexp.t -> 'a) ->
Sexplib0.Sexp.t ->
('a, Base.Error.t) Base.Result.t__float32 @@ portableSerialization and comparison of an Error force the error's lazy message.
val compare :
('a : value_or_null). (('a : value_or_null) -> ('a : value_or_null) -> int) ->
('a : value_or_null) Base.Or_error.t ->
('a : value_or_null) Base.Or_error.t ->
intval compare__local :
('a : value_or_null). (('a : value_or_null) @ local ->
('a : value_or_null) @ local ->
int) ->
('a : value_or_null) Base.Or_error.t @ local ->
('a : value_or_null) Base.Or_error.t @ local ->
intval equal :
('a : value_or_null). (('a : value_or_null) -> ('a : value_or_null) -> bool) ->
('a : value_or_null) Base.Or_error.t ->
('a : value_or_null) Base.Or_error.t ->
boolval equal__local :
('a : value_or_null). (('a : value_or_null) @ local ->
('a : value_or_null) @ local ->
bool) ->
('a : value_or_null) Base.Or_error.t @ local ->
('a : value_or_null) Base.Or_error.t @ local ->
boolval globalize :
('a : value_or_null). ('a @ local -> 'a) ->
'a Base.Or_error.t @ local ->
'a Base.Or_error.tval hash_fold_t :
('a : value_or_null). (Ppx_hash_lib.Std.Hash.state ->
('a : value_or_null) ->
Ppx_hash_lib.Std.Hash.state) ->
Ppx_hash_lib.Std.Hash.state ->
('a : value_or_null) Base.Or_error.t ->
Ppx_hash_lib.Std.Hash.stateval sexp_of_t :
('a : value_or_null). (('a : value_or_null) -> Sexplib0.Sexp.t) ->
('a : value_or_null) Base.Or_error.t ->
Sexplib0.Sexp.tval t_of_sexp :
('a : value_or_null). (Sexplib0.Sexp.t -> ('a : value_or_null)) ->
Sexplib0.Sexp.t ->
('a : value_or_null) Base.Or_error.tval t_sexp_grammar :
('a : value_or_null). ('a : value_or_null) Sexplib0.Sexp_grammar.t ->
('a : value_or_null) Base.Or_error.t Sexplib0.Sexp_grammar.t @@ portableApplicative functions don't have quite the same semantics as Applicative.Of_Monad(Or_error) would give -- apply (Error e1) (Error e2) returns the combination of e1 and e2, whereas it would only return e1 if it were defined using bind.
include Base.Applicative.S__'value_or_null_mod_maybe_null'__local
with type ('a : value_or_null) t := 'a Base.Or_error.t
Applies the functions in one t to the values in another. Well-behaved applicatives satisfy these "laws", using <*> as infix apply:
return Fn.id <*> tis equivalent totreturn Fn.compose <*> tf <*> tg <*> txis equivalent totf <*> (tg <*> tx)return f <*> return xis equivalent toreturn (f x)tf <*> return xis equivalent toreturn (fun f -> f x) <*> tf
Combines values in two ts as tuples. Using <*> as infix apply, equivalent to return (fun a b -> a, b) <*> ta <*> tb.
val map2 :
'a Base.Or_error.t ->
'b Base.Or_error.t ->
f:('a -> 'b -> 'c) @ local ->
'c Base.Or_error.tCombines the contents of two ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb.
val map3 :
'a Base.Or_error.t ->
'b Base.Or_error.t ->
'c Base.Or_error.t ->
f:('a -> 'b -> 'c -> 'd) @ local ->
'd Base.Or_error.tCombines the contents of three ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb <*> tc.
module Applicative_infix : sig ... endinclude Base.Invariant.S1 with type 'a t := 'a Base.Or_error.t
include Base.Monad.S__'value_or_null_mod_maybe_null'__local
with type ('a : value_or_null) t := 'a Base.Or_error.t
Convert a value to a t.
Sequences computations. bind t ~f computes f v for value(s) v in t. Well-behaved monads satisfy these "laws" (where ( >>= ) is the infix bind operator):
map t ~fis equivalent tobind t ~f:(fun x -> return (f x))return x >>= fis equivalent tof xt >>= returnis equivalent tot(t >>= f) >>= gis equivalent tot >>= fun x -> f x >>= g
Combines nested t into just one layer. Equivalent to bind t ~f:Fn.id.
Ignores contained values of t. Equivalent to map t ~f:ignore.
Combines a list of t.
Combines a list of t whose contents are unimportant.
Infix bind.
Infix map.
module Monad_infix : sig ... endval try_with :
('a : value_or_null). ?backtrace:bool ->
(unit -> 'a) @ local ->
'a Base.Or_error.t @@ portabletry_with f catches exceptions thrown by f and returns them in the Result.t as an Error.t. 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).
val try_with_join :
('a : value_or_null). ?backtrace:bool ->
(unit -> 'a Base.Or_error.t) @ local ->
'a Base.Or_error.t @@ portableok t returns None if t is an Error, and otherwise returns the contents of the Ok constructor.
ok_exn t throws an exception if t is an Error, and otherwise returns the contents of the Ok constructor.
val of_exn :
('a : value_or_null). ?backtrace:[ `Get | `This of string ] ->
exn ->
'a Base.Or_error.t @@ portableof_exn ?backtrace exn is Error (Error.of_exn ?backtrace exn).
val of_exn_result :
('a : value_or_null). ?backtrace:[ `Get | `This of string ] ->
('a, exn) Base.Result.t ->
'a Base.Or_error.t @@ portableof_exn_result ?backtrace (Ok a) = Ok a
of_exn_result ?backtrace (Error exn) = of_exn ?backtrace exn
val of_option :
('a : value_or_null). 'a option ->
error:Base.Error.t ->
'a Base.Or_error.t @@ portableof_option t returns Ok 'a if t is Some 'a, and otherwise returns the supplied error as Error error
val of_option_lazy :
('a : value_or_null). 'a option ->
error:Base.Error.t Base.Lazy.t ->
'a Base.Or_error.t @@ portableCalls of_option ~error:(Error.of_lazy_t error).
val of_option_lazy_sexp :
('a : value_or_null). 'a option ->
error:Base.Or_error.Sexp.t Base.Lazy.t ->
'a Base.Or_error.t @@ portableCalls of_option ~error:(Error.of_lazy_sexp error).
val of_option_lazy_string :
('a : value_or_null). 'a option ->
error:string Base.Lazy.t ->
'a Base.Or_error.t @@ portableCalls of_option ~error:(Error.of_lazy error).
val error :
'a ('b : value_or_null). ?here:Stdlib.Lexing.position ->
?strict:unit ->
string ->
'a ->
('a -> Base.Or_error.Sexp.t) ->
'b Base.Or_error.t @@ portableerror is a wrapper around Error.create:
error ?strict message a sexp_of_a = Error (Error.create ?strict message a sexp_of_a)As with Error.create, 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 ~strict:() to force sexp_of_a a to be computed immediately.
val error_s :
('a : value_or_null). Base.Or_error.Sexp.t ->
'a Base.Or_error.t @ portable @@ portableerror_string message is Error (Error.of_string message).
val errorf :
'a ('b : value_or_null). ('a, unit, string, 'b Base.Or_error.t)
Stdlib.format4 ->
'a @@ portableerrorf 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 error instead.
val errorf_portable :
'a ('b : value_or_null). ('a,
unit,
string,
unit ->
'b Base.Or_error.t @ portable)
Stdlib.format4 ->
'a @@ portableerrorf_portable format arg1 arg2 ... () is like errorf format arg1 arg2 ... but constructing a portable error.
val tag :
('a : value_or_null). 'a Base.Or_error.t ->
tag:string ->
'a Base.Or_error.t @@ portabletag t ~tag is Result.map_error t ~f:(Error.tag ~tag).
val tag_s :
('a : value_or_null). 'a Base.Or_error.t ->
tag:Base.Or_error.Sexp.t ->
'a Base.Or_error.t @@ portabletag_s is like tag with a sexp tag.
val tag_s_lazy :
('a : value_or_null). 'a Base.Or_error.t ->
tag:Base.Or_error.Sexp.t Base.Lazy.t ->
'a Base.Or_error.t @@ portabletag_s_lazy is like tag with a lazy sexp tag.
val tag_arg :
('a : value_or_null) ('b : value_or_null). 'a Base.Or_error.t ->
string ->
'b ->
('b -> Base.Or_error.Sexp.t) ->
'a Base.Or_error.t @@ portabletag_arg is like tag, with a tag that has a sexpable argument.
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.
val map :
('a : value_or_null) ('b : value_or_null). 'a Base.Or_error.t ->
f:('a -> 'b) @ local ->
'b Base.Or_error.t @@ portableval iter :
('a : value_or_null). 'a Base.Or_error.t ->
f:('a -> unit) @ local ->
unit @@ portableval iter_error :
('a : value_or_null). 'a Base.Or_error.t ->
f:(Base.Error.t -> unit) @ local ->
unit @@ portableval combine_errors :
('a : value_or_null). 'a Base.Or_error.t list ->
'a list Base.Or_error.t @@ portablecombine_errors ts returns Ok if every element in ts is Ok, else it returns Error with all the errors in ts. More precisely:
combine_errors [Ok a1; ...; Ok an] = Ok [a1; ...; an]combine_errors [...; Error e1; ...; Error en; ...] = Error (Error.of_list [e1; ...; en])
combine_errors_unit ts returns Ok if every element in ts is Ok (), else it returns Error with all the errors in ts, like combine_errors.
val filter_ok_at_least_one :
('a : value_or_null). 'a Base.Or_error.t list ->
'a list Base.Or_error.t @@ portablefilter_ok_at_least_one ts returns all values in ts that are Ok if there is at least one, otherwise it returns the same error as combine_errors ts. Returns a bespoke error when passed an empty list.
find_ok ts returns the first value in ts that is Ok, otherwise it returns the same error as combine_errors ts.
val find_map_ok :
('a : value_or_null) ('b : value_or_null). 'a list ->
f:('a -> 'b Base.Or_error.t) @ local ->
'b Base.Or_error.t @@ portablefind_map_ok l ~f returns the first value in l for which f returns Ok, otherwise it returns the same error as combine_errors (List.map l ~f). Returns a bespoke error when passed an empty list.