diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/util.ml | 9 | ||||
| -rw-r--r-- | lib/util.mli | 9 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/util.ml b/lib/util.ml index 6e22d6be57..0f79c10df1 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -87,8 +87,13 @@ let matrix_transpose mat = let identity x = x -let compose f g x = f (g x) -let (%) = compose +(** Function composition: the mathematical [∘] operator. + + So [g % f] is a synonym for [fun x -> g (f x)]. + + Also because [%] is right-associative, [h % g % f] means [fun x -> h (g (f x))]. + *) +let (%) f g x = f (g x) let const x _ = x diff --git a/lib/util.mli b/lib/util.mli index bf342c1e66..559874bb83 100644 --- a/lib/util.mli +++ b/lib/util.mli @@ -83,8 +83,15 @@ val matrix_transpose : 'a list list -> 'a list list (** {6 Functions. } *) val identity : 'a -> 'a -val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b + +(** Function composition: the mathematical [∘] operator. + + So [g % f] is a synonym for [fun x -> g (f x)]. + + Also because [%] is right-associative, [h % g % f] means [fun x -> h (g (f x))]. +*) val (%) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b + val const : 'a -> 'b -> 'a val iterate : ('a -> 'a) -> int -> 'a -> 'a val repeat : int -> ('a -> unit) -> 'a -> unit |
