Stdlib.Result(3) OCaml library Stdlib.Result(3)

# [NAME](#NAME)

Stdlib.Result - no description

# [Module](#Module)

Module Stdlib.Result

# [Documentation](#Documentation)

Module **Result**  
: **(module Stdlib\_\_Result)**

## [Results](#Results)

*type* **('a, 'e)** *t* = **('a, 'e) result** =  
| Ok **of** **'a**  
| Error **of** **'e**

The type for result values. Either a value **Ok v** or an error **Error e** .

*val ok* : **'a -&gt; ('a, 'e) result**

**ok v** is **Ok v** .

*val error* : **'e -&gt; ('a, 'e) result**

**error e** is **Error e** .

*val value* : **('a, 'e) result -&gt; default:'a -&gt; 'a**

**value r ~default** is **v** if **r** is **Ok v** and **default** otherwise.

*val get\_ok* : **('a, 'e) result -&gt; 'a**

**get\_ok r** is **v** if **r** is **Ok v** and raise otherwise.

**Raises Invalid\_argument** if **r** is **Error \_** .

*val get\_error* : **('a, 'e) result -&gt; 'e**

**get\_error r** is **e** if **r** is **Error e** and raise otherwise.

**Raises Invalid\_argument** if **r** is **Ok \_** .

*val bind* : **('a, 'e) result -&gt;** **('a -&gt; ('b, 'e) result) -&gt; ('b, 'e) result**

**bind r f** is **f v** if **r** is **Ok v** and **r** if **r** is **Error \_** .

*val join* : **(('a, 'e) result, 'e) result -&gt; ('a, 'e) result**

**join rr** is **r** if **rr** is **Ok r** and **rr** if **rr** is **Error \_** .

*val map* : **('a -&gt; 'b) -&gt; ('a, 'e) result -&gt; ('b, 'e) result**

**map f r** is **Ok (f v)** if **r** is **Ok v** and **r** if **r** is **Error \_** .

*val map\_error* : **('e -&gt; 'f) -&gt; ('a, 'e) result -&gt; ('a, 'f) result**

**map\_error f r** is **Error (f e)** if **r** is **Error e** and **r** if **r** is **Ok \_** .

*val fold* : **ok:('a -&gt; 'c) -&gt; error:('e -&gt; 'c) -&gt; ('a, 'e) result -&gt; 'c**

**fold ~ok ~error r** is **ok v** if **r** is **Ok v** and **error e** if **r** is **Error e** .

*val iter* : **('a -&gt; unit) -&gt; ('a, 'e) result -&gt; unit**

**iter f r** is **f v** if **r** is **Ok v** and **()** otherwise.

*val iter\_error* : **('e -&gt; unit) -&gt; ('a, 'e) result -&gt; unit**

**iter\_error f r** is **f e** if **r** is **Error e** and **()** otherwise.

## [Predicates and comparisons](#Predicates_and_comparisons)

*val is\_ok* : **('a, 'e) result -&gt; bool**

**is\_ok r** is **true** if and only if **r** is **Ok \_** .

*val is\_error* : **('a, 'e) result -&gt; bool**

**is\_error r** is **true** if and only if **r** is **Error \_** .

*val equal* : **ok:('a -&gt; 'a -&gt; bool) -&gt;** **error:('e -&gt; 'e -&gt; bool) -&gt;** **('a, 'e) result -&gt; ('a, 'e) result -&gt; bool**

**equal ~ok ~error r0 r1** tests equality of **r0** and **r1** using **ok** and **error** to respectively compare values wrapped by **Ok \_** and **Error \_** .

*val compare* : **ok:('a -&gt; 'a -&gt; int) -&gt;** **error:('e -&gt; 'e -&gt; int) -&gt;** **('a, 'e) result -&gt; ('a, 'e) result -&gt; int**

**compare ~ok ~error r0 r1** totally orders **r0** and **r1** using **ok** and **error** to respectively compare values wrapped by **Ok \_** and **Error \_** . **Ok \_** values are smaller than **Error \_** values.

## [Converting](#Converting)

*val to\_option* : **('a, 'e) result -&gt; 'a option**

**to\_option r** is **r** as an option, mapping **Ok v** to **Some v** and **Error \_** to **None** .

*val to\_list* : **('a, 'e) result -&gt; 'a list**

**to\_list r** is **\[v]** if **r** is **Ok v** and **\[]** otherwise.

*val to\_seq* : **('a, 'e) result -&gt; 'a Seq.t**

**to\_seq r** is **r** as a sequence. **Ok v** is the singleton sequence containing **v** and **Error \_** is the empty sequence.

2026-09-15 OCamldoc

---

Document: Stdlib.Result(3o) from ocaml-4 4.14.4-r3 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
