-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgeneric_util_fun.mli
More file actions
88 lines (66 loc) · 2.4 KB
/
Copy pathgeneric_util_fun.mli
File metadata and controls
88 lines (66 loc) · 2.4 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(** Function combinators. *)
(** Constant function, ignore the second argument. *)
val const : 'a -> 'b -> 'a
(** Identity function *)
val id : 'a -> 'a
(** flip the arguments of a function *)
val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c
val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c
val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c
(** {2 Function composition}
The functions [res_n] compose a unary function to
the result of a [n]-ary function, so that:
{[
res_n g f x_0 .. x_{n-1} == g (f x_0 ... x_{n-1})
]}
*)
val res0 : ('a -> 'b) -> 'a -> 'b
val res1 : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
val res2 : ('a -> 'b) -> ('c -> 'd -> 'a) -> 'c -> 'd -> 'b
val res3 : ('a -> 'b) -> ('c -> 'd -> 'e -> 'a) -> 'c -> 'd -> 'e -> 'b
val res4 : ('a -> 'b) -> ('c -> 'd -> 'e -> 'f -> 'a) -> 'c -> 'd -> 'e -> 'f -> 'b
val res5 :
('a -> 'b) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'a) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'b)
val res6 :
('a -> 'b) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'a) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'b)
val res7 :
('a -> 'b) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'a) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'b)
val res8 :
('a -> 'b) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'a) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'b)
val res9 :
('a -> 'b) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k -> 'a) ->
('c -> 'd -> 'e -> 'f -> 'g -> 'h -> 'i -> 'j -> 'k -> 'b)
(** [opres (^) f g x = f x ^ g x] *)
val opres : ('a -> 'b -> 'c) -> ('d -> 'a) -> ('d -> 'b) -> 'd -> 'c
(** [opon (^) f x y = f x ^ f y] *)
val opon : ('a -> 'a -> 'b) -> ('c -> 'a) -> 'c -> 'c -> 'b
(** {3 Composition and Point-Free Operators} *)
(** [(g -< f) x = g (f x)] *)
val ( -< ) : ('a -> 'b) -> ('c -> 'a) -> ('c -> 'b)
(** [(f >- g) x = g (f x)] *)
val ( >- ) : ('a -> 'b) -> ('b -> 'c) -> ('a -> 'c)
(** [(f >>. g) x = f x ; g x] *)
val ( >>. ) : ('a -> 'b) -> ('a -> 'c) -> ('a -> 'c)
(** [(f &&. g) x = f x && g x] *)
val ( &&. ) : ('a -> bool) -> ('a -> bool) -> ('a -> bool)
(** {2 Isomorphisms}
*)
(** An isomorphism is given by a bijection and its inverse,
it must be true that: {[fwd (bck x) = bck (fwd x) = x]}
*)
type ('a, 'b) iso = { fwd : 'a -> 'b; bck : 'b -> 'a; }
(** The identity isomorphism *)
val iso_id : ('a, 'a) iso
(** {2 Functions on ordered types}
*)
(** {[in_range x (a, b) = x >= a && x <= b]} *)
val in_range : 'a -> 'a * 'a -> bool