1Stdlib.Fun(3)                    OCaml library                   Stdlib.Fun(3)
2
3
4

NAME

6       Stdlib.Fun - no description
7

Module

9       Module   Stdlib.Fun
10

Documentation

12       Module Fun
13        : (module Stdlib__Fun)
14
15
16
17
18
19
20
21
22
23   Combinators
24       val id : 'a -> 'a
25
26
27       id is the identity function. For any argument x , id x is x .
28
29
30
31       val const : 'a -> 'b -> 'a
32
33
34       const  c  is a function that always returns the value c . For any argu‐
35       ment x , (const c) x is c .
36
37
38
39       val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c
40
41
42       flip f reverses the argument order of the binary function f .  For  any
43       arguments x and y , (flip f) x y is f y x .
44
45
46
47       val negate : ('a -> bool) -> 'a -> bool
48
49
50       negate p is the negation of the predicate function p . For any argument
51       x , (negate p) x is not (p x) .
52
53
54
55
56   Exception handling
57       val protect : finally:(unit -> unit) -> (unit -> 'a) -> 'a
58
59
60       protect ~finally work invokes work () and then finally ()  before  work
61       ()  returns  with its value or an exception. In the latter case the ex‐
62       ception is re-raised after finally () . If finally () raises an  excep‐
63       tion, then the exception Fun.Finally_raised is raised instead.
64
65
66       protect can be used to enforce local invariants whether work () returns
67       normally or raises an exception. However, it does not  protect  against
68       unexpected  exceptions raised inside finally () such as Out_of_memory ,
69       Stack_overflow , or asynchronous exceptions raised by  signal  handlers
70       (e.g.  Sys.Break ).
71
72       Note: It is a programming error if other kinds of exceptions are raised
73       by finally , as any exception raised in work () will  be  lost  in  the
74       event  of  a  Fun.Finally_raised  exception. Therefore, one should make
75       sure to handle those inside the finally.
76
77
78
79       exception Finally_raised of exn
80
81
82
83       Finally_raised exn is raised by  protect  ~finally  work  when  finally
84       raises  an  exception exn . This exception denotes either an unexpected
85       exception or a programming error. As a general  rule,  one  should  not
86       catch a Finally_raised exception except as part of a catch-all handler.
87
88
89
90
91
92OCamldoc                          2022-02-04                     Stdlib.Fun(3)
Impressum