jon.recoil.org

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.t
module Sexp := Base__.Sexp0
Sourcetype ('a : value_or_null) t = ('a, Error.t) Result.t

Serialization and comparison of an Error force the error's lazy message.

Sourceval compare : ('a : value_or_null). ('a -> 'a -> int) -> 'a t -> 'a t -> int
Sourceval compare__local : ('a : value_or_null). ('a @ local -> 'a @ local -> int) -> 'a t @ local -> 'a t @ local -> int
Sourceval equal : ('a : value_or_null). ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
Sourceval equal__local : ('a : value_or_null). ('a @ local -> 'a @ local -> bool) -> 'a t @ local -> 'a t @ local -> bool
Sourceval globalize : ('a : value_or_null). ('a @ local -> 'a) -> 'a t @ local -> 'a t
Sourceval sexp_of_t : ('a : value_or_null). ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
Sourceval sexp_of_t__stack : ('a : value_or_null). ('a @ local -> Sexplib0.Sexp.t @ local) -> 'a t @ local -> Sexplib0.Sexp.t @ local
Sourceval t_of_sexp : ('a : value_or_null). (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t
Sourceval t_sexp_grammar : ('a : value_or_null). 'a Sexplib0.Sexp_grammar.t -> 'a t Sexplib0.Sexp_grammar.t @@ portable

Applicative 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 Applicative.S__'value_or_null_mod_maybe_null'__local with type ('a : value_or_null) t := 'a t
Sourceval apply : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'p 'q. ('a -> 'b) t -> 'a t -> 'b 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 <*> t is equivalent to t
  • return Fn.compose <*> tf <*> tg <*> tx is equivalent to tf <*> (tg <*> tx)
  • return f <*> return x is equivalent to return (f x)
  • tf <*> return x is equivalent to return (fun f -> f x) <*> tf
Sourceval both : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'p 'q. 'a t -> 'b t -> ('a * 'b) t

Combines values in two ts as tuples. Using <*> as infix apply, equivalent to return (fun a b -> a, b) <*> ta <*> tb.

Sourceval map2 : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) ('c : value_or_null mod maybe_null) 'p 'q. 'a t -> 'b t -> f:('a -> ('b -> 'c) @ local) @ local -> 'c t

Combines the contents of two ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb.

Sourceval map3 : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) ('c : value_or_null mod maybe_null) ('d : value_or_null mod maybe_null) 'p 'q. 'a t -> 'b t -> 'c t -> f:('a -> ('b -> ('c -> 'd) @ local) @ local) @ local -> 'd t

Combines the contents of three ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb <*> tc.

Sourceval (<*>) : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'p 'q. ('a -> 'b) t -> 'a t -> 'b t
Sourceval (<*) : ('a : value_or_null mod maybe_null) 'p 'q. 'a t -> unit t -> 'a t
Sourceval (*>) : ('a : value_or_null mod maybe_null) 'p 'q. unit t -> 'a t -> 'a t
Sourcemodule Applicative_infix : sig ... end
include Invariant.S1 with type 'a t := 'a t
Sourceval invariant : ('a -> unit) -> 'a t -> unit
include Monad.S__'value_or_null_mod_maybe_null'__local with type ('a : value_or_null) t := 'a t
Sourceval join : ('a : value_or_null mod maybe_null) 'i 'j 'k 'p 'q. 'a t t -> 'a t

Combines nested t into just one layer. Equivalent to bind t ~f:Fn.id.

Sourceval ignore_m : ('a : value_or_null mod maybe_null) 'i 'j 'p 'q. 'a t -> unit t

Ignores contained values of t. Equivalent to map t ~f:ignore.

Sourceval all : ('a : value_or_null mod maybe_null) 'i 'p 'q. 'a t list -> 'a list t

Combines a list of t.

Sourceval all_unit : 'i 'p 'q. unit t list -> unit t

Combines a list of t whose contents are unimportant.

Sourceval (>>=) : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'i 'j 'k 'p 'q. 'a t -> ('a -> 'b t) @ local -> 'b t

Infix bind.

Sourceval (>>|) : ('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'i 'j 'p 'q. 'a t -> ('a -> 'b) @ local -> 'b t

Infix map.

Sourcemodule Monad_infix : sig ... end
Sourcemodule Let_syntax : sig ... end
Sourceval is_ok : ('a : value_or_null). 'a t -> bool @@ portable
Sourceval is_error : ('a : value_or_null). 'a t -> bool @@ portable
Sourceval try_with : ('a : value_or_null). ?backtrace:bool -> (unit -> 'a) @ local once -> 'a t @@ portable

try_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).

Sourceval try_with_join : ('a : value_or_null). ?backtrace:bool -> (unit -> 'a t) @ local once -> 'a t @@ portable
Sourceval ok : ('ok : value_or_null). 'ok t -> 'ok option @@ portable

ok t returns None if t is an Error, and otherwise returns the contents of the Ok constructor.

Sourceval ok_or_null : 'ok t -> 'ok or_null @@ portable [@@zero_alloc]

ok_or_null t returns Null if t is an Error, and otherwise returns the contents of the Ok constructor wrapped in This.

Sourceval ok_exn : ('a : value_or_null). 'a t -> 'a @@ portable

ok_exn t throws an exception if t is an Error, and otherwise returns the contents of the Ok constructor.

Sourceval of_exn : ('a : value_or_null). ?backtrace:[ `Get | `This of string ] -> exn -> 'a t @@ portable

of_exn ?backtrace exn is Error (Error.of_exn ?backtrace exn).

Sourceval of_exn_result : ('a : value_or_null). ?backtrace:[ `Get | `This of string ] -> ('a, exn) Result.t -> 'a t @@ portable

of_exn_result ?backtrace (Ok a) = Ok a

of_exn_result ?backtrace (Error exn) = of_exn ?backtrace exn

Sourceval of_option : ('a : value_or_null). 'a option -> error:Error.t -> 'a t @@ portable

of_option t returns Ok 'a if t is Some 'a, and otherwise returns the supplied error as Error error

Sourceval of_option_lazy : ('a : value_or_null). 'a option -> error:Error.t Lazy.t -> 'a t @@ portable

Calls of_option ~error:(Error.of_lazy_t error).

Sourceval of_option_lazy_sexp : ('a : value_or_null). 'a option -> error:Sexp.t Lazy.t -> 'a t @@ portable

Calls of_option ~error:(Error.of_lazy_sexp error).

Sourceval of_option_lazy_string : ('a : value_or_null). 'a option -> error:string Lazy.t -> 'a t @@ portable

Calls of_option ~error:(Error.of_lazy error).

Sourceval of_or_null : 'a or_null -> error:Error.t -> 'a t @@ portable

of_or_null t ~error returns Ok 'a if t is This 'a, and otherwise returns the supplied error as Error error.

Sourceval of_or_null_lazy : 'a or_null -> error:Error.t Lazy.t -> 'a t @@ portable

Calls of_or_null ~error:(Error.of_lazy_t error).

Sourceval of_or_null_lazy_sexp : 'a or_null -> error:Sexp.t Lazy.t -> 'a t @@ portable

Calls of_or_null ~error:(Error.of_lazy_sexp error).

Sourceval of_or_null_lazy_string : 'a or_null -> error:string Lazy.t -> 'a t @@ portable

Calls of_or_null ~error:(Error.of_lazy error).

Sourceval error : ('a : value_or_null mod uncontended) ('b : value_or_null). ?here: Lexing.position -> ?strict:unit -> string -> 'a -> ('a -> Sexp.t) -> 'b t @@ portable

error 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.

Sourceval error_s : ('a : value_or_null). Sexp.t -> 'a t @ portable @@ portable
Sourceval error_string : ('a : value_or_null). string -> 'a t @ portable @@ portable

error_string message is Error (Error.of_string message).

Sourceval errorf : 'a ('b : value_or_null). ('a, unit, string, 'b t) format4 -> 'a @@ portable

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 error instead.

Sourceval errorf_portable : 'a ('b : value_or_null). ('a, unit, string, unit -> 'b t @ portable) format4 -> 'a @@ portable

errorf_portable format arg1 arg2 ... () is like errorf format arg1 arg2 ... but constructing a portable error.

Sourceval tag : ('a : value_or_null). 'a t -> tag:string -> 'a t @@ portable

tag t ~tag is Result.map_error t ~f:(Error.tag ~tag).

Sourceval tag_s : ('a : value_or_null). 'a t -> tag:Sexp.t -> 'a t @@ portable

tag_s is like tag with a sexp tag.

Sourceval tag_lazy : ('a : value_or_null). 'a t -> tag:string Lazy.t -> 'a t @@ portable

tag_lazy is like tag with a lazy tag.

Sourceval tag_s_lazy : ('a : value_or_null). 'a t -> tag:Sexp.t Lazy.t -> 'a t @@ portable

tag_s_lazy is like tag with a lazy sexp tag.

Sourceval tag_arg : ('a : value_or_null) ('b : value_or_null). 'a t -> string -> 'b -> ('b -> Sexp.t) -> 'a t @@ portable

tag_arg is like tag, with a tag that has a sexpable argument.

Sourceval unimplemented : ('a : value_or_null). string -> 'a t @ portable @@ portable

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.

Sourceval return : ('a : value_or_null). 'a -> 'a t @@ portable
Sourceval bind : ('a : value_or_null) ('b : value_or_null). 'a t -> f:('a -> 'b t) @ local -> 'b t @@ portable
Sourceval map : ('a : value_or_null) ('b : value_or_null). 'a t -> f:('a -> 'b) @ local -> 'b t @@ portable
Sourceval iter : ('a : value_or_null). 'a t -> f:('a -> unit) @ local once -> unit @@ portable
Sourceval iter_error : ('a : value_or_null). 'a t -> f:(Error.t -> unit) @ local once -> unit @@ portable
Sourceval combine_errors : ('a : value_or_null). 'a t list -> 'a list t @@ portable

combine_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])
Sourceval combine_errors_unit : unit t list -> unit t @@ portable

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.

Sourceval filter_ok_at_least_one : ('a : value_or_null). 'a t list -> 'a list t @@ portable

filter_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.

Sourceval find_ok : ('a : value_or_null). 'a t list -> 'a t @@ portable

find_ok ts returns the first value in ts that is Ok, otherwise it returns the same error as combine_errors ts.

Sourceval find_map_ok : ('a : value_or_null) ('b : value_or_null). 'a list -> f:('a -> 'b t) @ local -> 'b t @@ portable

find_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.