639 lines
5.7 KiB
HTML
639 lines
5.7 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Result</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Result</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Result - Result values.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Result
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Result</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Result values.
|
|
<P>
|
|
Result values handle computation results and errors in an explicit
|
|
and declarative manner without resorting to exceptions.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.08
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Results</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type </I>
|
|
|
|
<B>('a, 'e)</B>
|
|
|
|
<I>t </I>
|
|
|
|
=
|
|
<B>('a, 'e) result</B>
|
|
|
|
=
|
|
<BR> | Ok
|
|
<B>of </B>
|
|
|
|
<B>'a</B>
|
|
|
|
<BR> | Error
|
|
<B>of </B>
|
|
|
|
<B>'e</B>
|
|
|
|
<BR>
|
|
<P>
|
|
The type for result values. Either a value
|
|
<B>Ok v</B>
|
|
|
|
or an error
|
|
<B>Error e</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ok </I>
|
|
|
|
:
|
|
<B>'a -> ('a, 'e) result</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>ok v</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val error </I>
|
|
|
|
:
|
|
<B>'e -> ('a, 'e) result</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>error e</B>
|
|
|
|
is
|
|
<B>Error e</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val value </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> default:'a -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>value r ~default</B>
|
|
|
|
is
|
|
<B>v</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<B>default</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_ok </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_ok r</B>
|
|
|
|
is
|
|
<B>v</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<P>
|
|
<P>
|
|
<B>Raises Invalid_argument</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_error </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> 'e</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>get_error r</B>
|
|
|
|
is
|
|
<B>e</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error e</B>
|
|
|
|
and
|
|
<P>
|
|
<P>
|
|
<B>Raises Invalid_argument</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val bind </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -></B>
|
|
|
|
<B>('a -> ('b, 'e) result) -> ('b, 'e) result</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>bind r f</B>
|
|
|
|
is
|
|
<B>f v</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<B>r</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val join </I>
|
|
|
|
:
|
|
<B>(('a, 'e) result, 'e) result -> ('a, 'e) result</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>join rr</B>
|
|
|
|
is
|
|
<B>r</B>
|
|
|
|
if
|
|
<B>rr</B>
|
|
|
|
is
|
|
<B>Ok r</B>
|
|
|
|
and
|
|
<B>rr</B>
|
|
|
|
if
|
|
<B>rr</B>
|
|
|
|
is
|
|
<B>Error _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val map </I>
|
|
|
|
:
|
|
<B>('a -> 'b) -> ('a, 'e) result -> ('b, 'e) result</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>map f r</B>
|
|
|
|
is
|
|
<B>Ok (f v)</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<B>r</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val map_error </I>
|
|
|
|
:
|
|
<B>('e -> 'f) -> ('a, 'e) result -> ('a, 'f) result</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>map_error f r</B>
|
|
|
|
is
|
|
<B>Error (f e)</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error e</B>
|
|
|
|
and
|
|
<B>r</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fold </I>
|
|
|
|
:
|
|
<B>ok:('a -> 'c) -> error:('e -> 'c) -> ('a, 'e) result -> 'c</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>fold ~ok ~error r</B>
|
|
|
|
is
|
|
<B>ok v</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<B>error e</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error e</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val iter </I>
|
|
|
|
:
|
|
<B>('a -> unit) -> ('a, 'e) result -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>iter f r</B>
|
|
|
|
is
|
|
<B>f v</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<B>()</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val iter_error </I>
|
|
|
|
:
|
|
<B>('e -> unit) -> ('a, 'e) result -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>iter_error f r</B>
|
|
|
|
is
|
|
<B>f e</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error e</B>
|
|
|
|
and
|
|
<B>()</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Predicates and comparisons</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val is_ok </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>is_ok r</B>
|
|
|
|
is
|
|
<B>true</B>
|
|
|
|
iff
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val is_error </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>is_error r</B>
|
|
|
|
is
|
|
<B>true</B>
|
|
|
|
iff
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Error _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val equal </I>
|
|
|
|
:
|
|
<B>ok:('a -> 'a -> bool) -></B>
|
|
|
|
<B>error:('e -> 'e -> bool) -></B>
|
|
|
|
<B>('a, 'e) result -> ('a, 'e) result -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>equal ~ok ~error r0 r1</B>
|
|
|
|
tests equality of
|
|
<B>r0</B>
|
|
|
|
and
|
|
<B>r1</B>
|
|
|
|
using
|
|
<B>ok</B>
|
|
|
|
and
|
|
<B>error</B>
|
|
|
|
to respectively compare values wrapped by
|
|
<B>Ok _</B>
|
|
|
|
and
|
|
<B>Error _</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val compare </I>
|
|
|
|
:
|
|
<B>ok:('a -> 'a -> int) -></B>
|
|
|
|
<B>error:('e -> 'e -> int) -></B>
|
|
|
|
<B>('a, 'e) result -> ('a, 'e) result -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>compare ~ok ~error r0 r1</B>
|
|
|
|
totally orders
|
|
<B>r0</B>
|
|
|
|
and
|
|
<B>r1</B>
|
|
|
|
using
|
|
<B>ok</B>
|
|
|
|
and
|
|
<B>error</B>
|
|
|
|
to respectively compare values wrapped by
|
|
<B>Ok _ </B>
|
|
|
|
and
|
|
<B>Error _</B>
|
|
|
|
.
|
|
<B>Ok _</B>
|
|
|
|
values are smaller than
|
|
<B>Error _</B>
|
|
|
|
values.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Converting</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val to_option </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> 'a option</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>to_option r</B>
|
|
|
|
is
|
|
<B>r</B>
|
|
|
|
as an option, mapping
|
|
<B>Ok v</B>
|
|
|
|
to
|
|
<B>Some v</B>
|
|
|
|
and
|
|
<B>Error _</B>
|
|
|
|
to
|
|
<B>None</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val to_list </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> 'a list</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>to_list r</B>
|
|
|
|
is
|
|
<B>[v]</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is
|
|
<B>Ok v</B>
|
|
|
|
and
|
|
<B>[]</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val to_seq </I>
|
|
|
|
:
|
|
<B>('a, 'e) result -> 'a Seq.t</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>to_seq r</B>
|
|
|
|
is
|
|
<B>r</B>
|
|
|
|
as a sequence.
|
|
<B>Ok v</B>
|
|
|
|
is the singleton sequence
|
|
containing
|
|
<B>v</B>
|
|
|
|
and
|
|
<B>Error _</B>
|
|
|
|
is the empty sequence.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">Results</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Predicates and comparisons</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">Converting</A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:54 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|