From df0e442956864a44b14732a57f1ed712b2850bb4 Mon Sep 17 00:00:00 2001 From: Ben Bellick Date: Sat, 24 Aug 2024 10:26:01 -0500 Subject: [PATCH 1/3] predicate combinators: and_p and or_p --- src/core/CCFun.ml | 4 ++++ src/core/CCFun.mli | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/core/CCFun.ml b/src/core/CCFun.ml index 65c9a5d59..8a3e5375d 100644 --- a/src/core/CCFun.ml +++ b/src/core/CCFun.ml @@ -8,6 +8,10 @@ include Sys include Stdlib include Fun + +let[@inline] and_p f g x = (f x) && (g x) +let[@inline] or_p f g x = (f x) || (g x) + let[@inline] compose f g x = g (f x) let[@inline] compose_binop f g x y = g (f x) (f y) let[@inline] curry f x y = f (x, y) diff --git a/src/core/CCFun.mli b/src/core/CCFun.mli index fa69904f8..913f28e0b 100644 --- a/src/core/CCFun.mli +++ b/src/core/CCFun.mli @@ -5,6 +5,16 @@ include module type of Fun (** @inline *) +val and_p : ('a -> bool) -> ('a -> bool) -> 'a -> bool +(** [and_p f g x] is [(f x) && (g x)]. + Produces a predicate which is a conjunction of the two predicates. +*) + +val or_p : ('a -> bool) -> ('a -> bool) -> 'a -> bool +(** [or_p f g x] is [(f x) || (g x)]. + Produces a predicate which is a disjunction of the two predicates. +*) + val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c (** [compose f g x] is [g (f x)]. Composition. *) From 1dc046c6e9313f21ba96c9fc3d80db0ac978fd2b Mon Sep 17 00:00:00 2001 From: Ben Bellick Date: Sat, 24 Aug 2024 10:53:59 -0500 Subject: [PATCH 2/3] fix formatting --- src/core/CCFun.ml | 6 ++---- src/core/CCFun.mli | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/CCFun.ml b/src/core/CCFun.ml index 8a3e5375d..f36af982c 100644 --- a/src/core/CCFun.ml +++ b/src/core/CCFun.ml @@ -8,10 +8,8 @@ include Sys include Stdlib include Fun - -let[@inline] and_p f g x = (f x) && (g x) -let[@inline] or_p f g x = (f x) || (g x) - +let[@inline] and_p f g x = f x && g x +let[@inline] or_p f g x = f x || g x let[@inline] compose f g x = g (f x) let[@inline] compose_binop f g x y = g (f x) (f y) let[@inline] curry f x y = f (x, y) diff --git a/src/core/CCFun.mli b/src/core/CCFun.mli index 913f28e0b..c4f6d49be 100644 --- a/src/core/CCFun.mli +++ b/src/core/CCFun.mli @@ -9,12 +9,12 @@ val and_p : ('a -> bool) -> ('a -> bool) -> 'a -> bool (** [and_p f g x] is [(f x) && (g x)]. Produces a predicate which is a conjunction of the two predicates. *) - + val or_p : ('a -> bool) -> ('a -> bool) -> 'a -> bool (** [or_p f g x] is [(f x) || (g x)]. Produces a predicate which is a disjunction of the two predicates. *) - + val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c (** [compose f g x] is [g (f x)]. Composition. *) From c6cb57223035a90f86be065f29c8713c40207f05 Mon Sep 17 00:00:00 2001 From: Benjamin Bellick Date: Tue, 3 Sep 2024 11:59:43 -0500 Subject: [PATCH 3/3] and_p -> and_pred, or_p -> or_pred --- src/core/CCFun.ml | 5 +++-- src/core/CCFun.mli | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/CCFun.ml b/src/core/CCFun.ml index f36af982c..1718aa7f1 100644 --- a/src/core/CCFun.ml +++ b/src/core/CCFun.ml @@ -8,10 +8,11 @@ include Sys include Stdlib include Fun -let[@inline] and_p f g x = f x && g x -let[@inline] or_p f g x = f x || g x +let[@inline] and_pred f g x = f x && g x +let[@inline] or_pred f g x = f x || g x let[@inline] compose f g x = g (f x) let[@inline] compose_binop f g x y = g (f x) (f y) + let[@inline] curry f x y = f (x, y) let[@inline] uncurry f (x, y) = f x y diff --git a/src/core/CCFun.mli b/src/core/CCFun.mli index c4f6d49be..1c20937b5 100644 --- a/src/core/CCFun.mli +++ b/src/core/CCFun.mli @@ -5,12 +5,12 @@ include module type of Fun (** @inline *) -val and_p : ('a -> bool) -> ('a -> bool) -> 'a -> bool +val and_pred : ('a -> bool) -> ('a -> bool) -> 'a -> bool (** [and_p f g x] is [(f x) && (g x)]. Produces a predicate which is a conjunction of the two predicates. *) -val or_p : ('a -> bool) -> ('a -> bool) -> 'a -> bool +val or_pred : ('a -> bool) -> ('a -> bool) -> 'a -> bool (** [or_p f g x] is [(f x) || (g x)]. Produces a predicate which is a disjunction of the two predicates. *)