Stdlib.Result(3)
π NAME π
Stdlib.Result β and the description is literally just βno description,β bestie. Iconic mysterious behavior. This is the Stdlib.Result(3) page from the OCaml library, and we are about to go through every single type and val, no skips, no cap.
π Module π
The module is Stdlib.Result. Main character energy only.
π Documentation π
Okay so the docs say Module Result, and it is aliased like this:
Module Result
: (module Stdlib__Result)
Then we get into it:
β¨ Results β¨
The type for result values is literally:
type ('a, 'e) t = ('a, 'e) result =
| Ok of 'a
| Error of 'e
It is the type for result values: either a value Ok v or an error Error e. Periodt.
val ok : 'a -> ('a, 'e) resultβok visOk v. Slay.val error : 'e -> ('a, 'e) resultβerror eisError e.val value : ('a, 'e) result -> default:'a -> 'aβvalue r ~defaultisvifrisOk v, anddefaultotherwise.val get_ok : ('a, 'e) result -> 'aβget_ok risvifrisOk v, and otherwise it raises.
RaisesInvalid_argumentifrisError _.
val get_ok' : ('a, string) result -> 'aβget_ok'is likeResult.get_ok, but in case of error it uses the error message for raisingInvalid_argument. Since5.4.val get_error : ('a, 'e) result -> 'eβget_error riseifrisError e, and otherwise it raises.
RaisesInvalid_argumentifrisOk _.
val error_to_failure : ('a, string) result -> 'aβerror_to_failure risvifrisOk v, and raisesFailure eifrisError e. Since5.4.val bind : ('a, 'e) result -> ('a -> ('b, 'e) result) -> ('b, 'e) resultβbind r fisf vifrisOk v, andrifrisError _.val join : (('a, 'e) result, 'e) result -> ('a, 'e) resultβjoin rrisrifrrisOk r, andrrifrrisError _.val map : ('a -> 'b) -> ('a, 'e) result -> ('b, 'e) resultβmap f risOk (f v)ifrisOk v, andrifrisError _.val product : ('a, 'e) result -> ('b, 'e) result -> ('a * 'b, 'e) resultβproduct r0 r1isOk (v0, v1)ifr0isOk v0andr1isOk v1, and otherwise returns the error ofr0, if any, or the error ofr1. Since5.4.val map_error : ('e -> 'f) -> ('a, 'e) result -> ('a, 'f) resultβmap_error f risError (f e)ifrisError e, andrifrisOk _.val fold : ok:('a -> 'c) -> error:('e -> 'c) -> ('a, 'e) result -> 'cβfold ~ok ~error risok vifrisOk v, anderror eifrisError e.val retract : ('a, 'a) result -> 'aβretract risvifrisOk vorError v. Since5.4.val iter : ('a -> unit) -> ('a, 'e) result -> unitβiter f risf vifrisOk v, and()otherwise.val iter_error : ('e -> unit) -> ('a, 'e) result -> unitβiter_error f risf eifrisError e, and()otherwise.
π Predicates and comparisons π
val is_ok : ('a, 'e) result -> boolβis_ok ristrueif and only ifrisOk _.val is_error : ('a, 'e) result -> boolβis_error ristrueif and only ifrisError _.val equal : ok:('a -> 'a -> bool) -> error:('e -> 'e -> bool) -> ('a, 'e) result -> ('a, 'e) result -> boolβequal ~ok ~error r0 r1tests equality ofr0andr1usingokanderrorto respectively compare values wrapped byOk _andError _.val compare : ok:('a -> 'a -> int) -> error:('e -> 'e -> int) -> ('a, 'e) result -> ('a, 'e) result -> intβcompare ~ok ~error r0 r1totally ordersr0andr1usingokanderrorto respectively compare values wrapped byOk _andError _.Ok _values are smaller thanError _values. That is the rule, bestie.
π¦ Converting π¦
val to_option : ('a, 'e) result -> 'a optionβto_option risras an option, mappingOk vtoSome vandError _toNone.val to_list : ('a, 'e) result -> 'a listβto_list ris[v]ifrisOk v, and[]otherwise.val to_seq : ('a, 'e) result -> 'a Seq.tβto_seq risras a sequence.Ok vis the singleton sequence containingv, andError _is the empty sequence.
π Syntax π
module Syntax : sig endβ Binding operators. See manual section12.23for details. Since5.4.
Okay bestie, that is the whole Stdlib.Result page β every val, every predicate, every conversion, and the syntax module, all of it. Source/version is OCamldoc, dated 2026-06-22, and the footer was Stdlib.Result(3). Byeee, go slay your result types π
β¨
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms