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

NAME

6       Fun - Function manipulation.
7

Module

9       Module   Fun
10

Documentation

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