-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgeneric_util_fun.ml
More file actions
38 lines (33 loc) · 1.14 KB
/
Copy pathgeneric_util_fun.ml
File metadata and controls
38 lines (33 loc) · 1.14 KB
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
37
38
let const x _ = x
let id x = x
let flip f x y = f y x
let curry f x y = f (x,y)
let uncurry f (x,y) = f x y
(* composition operators.
"resN" stands for:
apply a function on the result of an "n"-ary function *)
let res0 f g = f g
let res1 f g x = f (g x)
(* res2 f g x y = f (g x y) *)
(* res1 res1 res1 f g x y == res1 (res1 f) g x y == res1 f (g x) y == f (g x y) *)
let res2 f = res1 res1 res1 f
(* res1 res1 res2 f g x y z == res1 (res2 f) g x y z == res2 f (g x) y z == f (g x y z) *)
let res3 f = res1 res1 res2 f
let res4 f = res1 res1 res3 f
let res5 f = res1 res1 res4 f
let res6 f = res1 res1 res5 f
let res7 f = res1 res1 res6 f
let res8 f = res1 res1 res7 f
let res9 f = res1 res1 res8 f
let res10 f = res1 res1 res9 f
let opres op f g = fun x -> op (f x) (g x)
let opon op f x y = op (f x) (f y)
(* Composition and point-free operators *)
let (-<) f g x = f (g x)
let (>-) f g x = g (f x)
let (>>.) f g x = (f x ; g x)
let (&&.) f g x = f x && g x
(* forward and backward arrows, fwd (bck x) = bck (fwd x) = x *)
type ('a,'b) iso = {fwd : 'a -> 'b; bck : 'b -> 'a}
let iso_id = {fwd = id; bck= id}
let in_range x (a, b) = x >= a && x <= b