From cac98713f8b555b7944977451243d070bba9b48f Mon Sep 17 00:00:00 2001 From: solomon Date: Wed, 10 Jan 2024 00:14:13 -0800 Subject: [PATCH 1/2] Adds common infix operators for Semigroupal x --- src/Data/Bifunctor/Monoidal.hs | 32 +++++++++++++++++++++++++++++++- src/Data/Functor/Monoidal.hs | 9 --------- src/Data/Trifunctor/Monoidal.hs | 26 ++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/Data/Bifunctor/Monoidal.hs b/src/Data/Bifunctor/Monoidal.hs index 3083c98..4962125 100644 --- a/src/Data/Bifunctor/Monoidal.hs +++ b/src/Data/Bifunctor/Monoidal.hs @@ -1,6 +1,11 @@ module Data.Bifunctor.Monoidal ( -- * Semigroupal Semigroupal (..), + (|??|), + (|**|), + (|++|), + (|&&|), + (|+*|), -- * Unital Unital (..), @@ -28,7 +33,7 @@ import Data.Semigroupoid (Semigroupoid (..)) import Data.These (These (..), these) import Data.Tuple (fst, snd, uncurry) import Data.Void (Void, absurd) -import Prelude (Either (..)) +import Prelude (Either (..), curry) -------------------------------------------------------------------------------- @@ -212,6 +217,31 @@ instance Alternative f => Semigroupal (->) (,) Either (,) (Forget (f r)) where combine :: (Forget (f r) x y, Forget (f r) x' y') -> Forget (f r) (x, x') (Either y y') combine (Forget f, Forget g) = Forget $ \(x, x') -> f x <|> g x' +infixr 9 |??| + +(|??|) :: Semigroupal (->) t1 t2 (,) p => p a b -> p a' b' -> p (a `t1` a') (b `t2` b') +(|??|) = curry combine + +infixr 9 |**| + +(|**|) :: (Semigroupal (->) (,) (,) (,) p) => p a b -> p a' b' -> p (a, a') (b, b') +(|**|) = curry combine + +infixr 9 |++| + +(|++|) :: (Semigroupal (->) Either Either (,) p) => p a b -> p a' b' -> p (Either a a') (Either b b') +(|++|) = curry combine + +infixr 9 |&&| + +(|&&|) :: (Semigroupal (->) These These (,) p) => p a b -> p a' b' -> p (These a a') (These b b') +(|&&|) = curry combine + +infixr 9 |+*| + +(|+*|) :: (Semigroupal (->) Either (,) (,) p) => p a b -> p a' b' -> p (Either a a') (b, b') +(|+*|) = curry combine + -------------------------------------------------------------------------------- -- | Given monoidal categories \((\mathcal{C}, \otimes, I_{\mathcal{C}})\) and \((\mathcal{D}, \bullet, I_{\mathcal{D}})\). diff --git a/src/Data/Functor/Monoidal.hs b/src/Data/Functor/Monoidal.hs index c4be957..4ac2718 100644 --- a/src/Data/Functor/Monoidal.hs +++ b/src/Data/Functor/Monoidal.hs @@ -3,11 +3,8 @@ module Data.Functor.Monoidal Semigroupal (..), (|?|), (|*|), - type (|*|), (|+|), - type (|+|), (|&|), - type (|&|), -- * Unital Unital (..), @@ -341,12 +338,6 @@ infixr 3 |&| (|&|) :: Semigroupal (->) These (,) f => f a -> f b -> f (These a b) (|&|) = curry combine -type (|*|) = (,) - -type (|+|) = Either - -type (|&|) = These - -------------------------------------------------------------------------------- -- | Given monoidal categories \((\mathcal{C}, \otimes, I_{\mathcal{C}})\) and \((\mathcal{D}, \bullet, I_{\mathcal{D}})\). diff --git a/src/Data/Trifunctor/Monoidal.hs b/src/Data/Trifunctor/Monoidal.hs index 8bd07b4..f51de03 100644 --- a/src/Data/Trifunctor/Monoidal.hs +++ b/src/Data/Trifunctor/Monoidal.hs @@ -1,6 +1,10 @@ module Data.Trifunctor.Monoidal ( -- * Semigroupal Semigroupal (..), + (|***|), + (|*+*|), + (|+++|), + (|&&&|), -- * Unital Unital (..), @@ -13,6 +17,8 @@ where -------------------------------------------------------------------------------- import Control.Category.Tensor (Associative, Tensor) +import Prelude (curry, Either) +import Data.These (These) -------------------------------------------------------------------------------- @@ -49,6 +55,26 @@ class -- | A natural transformation \(\phi_{ABC,XYZ} : F\ A\ B\ C \bullet F\ X\ Y\ Z \to F\ (A \otimes X)\ (B \otimes Y) (C \otimes Z)\). combine :: to (f x y z) (f x' y' z') `cat` f (t1 x x') (t2 y y') (t3 z z') +infixr 9 |*+*| + +(|*+*|) :: (Semigroupal (->) (,) Either (,) (,) p) => p a b c -> p a' b c' -> p (a, a') (Either b b) (c, c') +(|*+*|) = curry combine + +infixr 9 |***| + +(|***|) :: (Semigroupal (->) (,) (,) (,) (,) p) => p a b c -> p a' b' c' -> p (a, a') (b, b') (c, c') +(|***|) = curry combine + +infixr 9 |+++| + +(|+++|) :: (Semigroupal (->) Either Either Either (,) p) => p a b c -> p a' b' c' -> p (Either a a') (Either b b') (Either c c') +(|+++|) = curry combine + +infixr 9 |&&&| + +(|&&&|) :: (Semigroupal (->) These These These (,) p) => p a b c -> p a' b' c' -> p (These a a') (These b b') (These c c') +(|&&&|) = curry combine + -------------------------------------------------------------------------------- -- | Given monoidal categories \((\mathcal{C}, \otimes, I_{\mathcal{C}})\) and \((\mathcal{D}, \bullet, I_{\mathcal{D}})\). From bfdb1d85df60f0c75f2562805eef96bfc877c525 Mon Sep 17 00:00:00 2001 From: solomon Date: Wed, 10 Jan 2024 00:14:24 -0800 Subject: [PATCH 2/2] Updates changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e66a4..54a8ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Revision history for monoidal-functors ## Upcoming +* Adds common infix operators for Semigroupal. ## 0.2.3.0 -- 2023-08-03 * Add support for GHC 9.6