-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathstdcompat__fun.ml.in
More file actions
36 lines (31 loc) · 912 Bytes
/
stdcompat__fun.ml.in
File metadata and controls
36 lines (31 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@BEGIN_FROM_4_08_0@
include Fun
@END_FROM_4_08_0@
@BEGIN_BEFORE_5_2_0@
let compose f g x = f (g x)
@END_BEFORE_5_2_0@
@BEGIN_BEFORE_4_08_0@
external id : 'a -> 'a = "%identity"
(** @since 4.08.0: external id : 'a -> 'a = "%identity" *)
let const c _ = c
let flip f x y = f y x
let negate f x = not (f x)
exception Finally_raised of exn
let protect ~finally f =
let value =
try
Stdcompat__pervasives.Ok (f ())
with exn ->
let bt = Stdcompat__printexc.get_raw_backtrace () in
Stdcompat__pervasives.Error (exn, bt) in
begin
try
finally ()
with exn ->
let bt = Stdcompat__printexc.get_raw_backtrace () in
Stdcompat__printexc.raise_with_backtrace (Finally_raised exn) bt
end;
match value with
| Stdcompat__pervasives.Ok result -> result
| Stdcompat__pervasives.Error (exn, bt) -> Stdcompat__printexc.raise_with_backtrace exn bt
@END_BEFORE_4_08_0@