273 lines
3.4 KiB
HTML
273 lines
3.4 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Stdlib.Fun</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Stdlib.Fun</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>
|
|
|
|
Stdlib.Fun - no description
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Stdlib.Fun
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Fun</B>
|
|
|
|
<BR> :
|
|
<B>(module Stdlib__fun)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Combinators</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val id </I>
|
|
|
|
:
|
|
<B>'a -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>id</B>
|
|
|
|
is the identity function. For any argument
|
|
<B>x</B>
|
|
|
|
,
|
|
<B>id x</B>
|
|
|
|
is
|
|
<B>x</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val const </I>
|
|
|
|
:
|
|
<B>'a -> 'b -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>const c</B>
|
|
|
|
is a function that always returns the value
|
|
<B>c</B>
|
|
|
|
. For any
|
|
argument
|
|
<B>x</B>
|
|
|
|
,
|
|
<B>(const c) x</B>
|
|
|
|
is
|
|
<B>c</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val flip </I>
|
|
|
|
:
|
|
<B>('a -> 'b -> 'c) -> 'b -> 'a -> 'c</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>flip f</B>
|
|
|
|
reverses the argument order of the binary function
|
|
<B>f</B>
|
|
|
|
. For any arguments
|
|
<B>x</B>
|
|
|
|
and
|
|
<B>y</B>
|
|
|
|
,
|
|
<B>(flip f) x y</B>
|
|
|
|
is
|
|
<B>f y x</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val negate </I>
|
|
|
|
:
|
|
<B>('a -> bool) -> 'a -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>negate p</B>
|
|
|
|
is the negation of the predicate function
|
|
<B>p</B>
|
|
|
|
. For any
|
|
argument
|
|
<B>x</B>
|
|
|
|
,
|
|
<B>(negate p) x</B>
|
|
|
|
is
|
|
<B>not (p x)</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Exception handling</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val protect </I>
|
|
|
|
:
|
|
<B>finally:(unit -> unit) -> (unit -> 'a) -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>protect ~finally work</B>
|
|
|
|
invokes
|
|
<B>work ()</B>
|
|
|
|
and then
|
|
<B>finally ()</B>
|
|
|
|
before
|
|
<B>work ()</B>
|
|
|
|
returns with its value or an exception. In the
|
|
latter case the exception is re-raised after
|
|
<B>finally ()</B>
|
|
|
|
. If
|
|
<B>finally ()</B>
|
|
|
|
raises an exception, then the exception
|
|
<B>Fun.Finally_raised</B>
|
|
|
|
is raised instead.
|
|
<P>
|
|
<P>
|
|
<B>protect</B>
|
|
|
|
can be used to enforce local invariants whether
|
|
<B>work ()</B>
|
|
|
|
returns normally or raises an exception. However, it does not
|
|
protect against unexpected exceptions raised inside
|
|
<B>finally ()</B>
|
|
|
|
such as
|
|
<B>Out_of_memory</B>
|
|
|
|
,
|
|
<B>Stack_overflow</B>
|
|
|
|
, or
|
|
asynchronous exceptions raised by signal handlers
|
|
(e.g.
|
|
<B>Sys.Break</B>
|
|
|
|
).
|
|
<P>
|
|
Note: It is a programming error if other kinds of exceptions
|
|
are raised by
|
|
<B>finally</B>
|
|
|
|
, as any exception raised in
|
|
<B>work ()</B>
|
|
|
|
will
|
|
be lost in the event of a
|
|
<B>Fun.Finally_raised</B>
|
|
|
|
exception. Therefore,
|
|
one should make sure to handle those inside the finally.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Finally_raised </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>exn</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<B>Finally_raised exn</B>
|
|
|
|
is raised by
|
|
<B>protect ~finally work</B>
|
|
|
|
when
|
|
<B>finally</B>
|
|
|
|
raises an exception
|
|
<B>exn</B>
|
|
|
|
. This exception denotes either
|
|
an unexpected exception or a programming error. As a general rule,
|
|
one should not catch a
|
|
<B>Finally_raised</B>
|
|
|
|
exception except as part of
|
|
a catch-all handler.
|
|
<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">Combinators</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Exception handling</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:57 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|