semigroupoids 6 → 6.0.2
raw patch · 10 files changed
Files
- CHANGELOG.markdown +16/−0
- semigroupoids.cabal +24/−24
- src/Data/Functor/Bind/Class.hs +19/−0
- src/Data/Functor/Contravariant/Conclude.hs +38/−15
- src/Data/Functor/Contravariant/Decide.hs +32/−6
- src/Data/Functor/Contravariant/Divise.hs +30/−8
- src/Data/Semigroup/Foldable.hs +1/−1
- src/Data/Semigroup/Traversable.hs +1/−1
- src/Data/Semigroup/Traversable/Class.hs +2/−21
- src/Data/Semigroupoid/Categorical.hs +4/−0
CHANGELOG.markdown view
@@ -1,3 +1,19 @@+6.0.2 [2026.01.10]+------------------+* Add `Apply` and `Bind` instances for strict and lazy `ST`.+* Remove unused `distributive` dependency.++6.0.1 [2024.05.04]+------------------+* Fix a build error when compiling with `-f-contravariant`.++6.0.0.1 [2023.03.16]+--------------------+* When building with GHC 9.6, require `transformers >= 0.6.1` and+ `containers >= 0.6.7`. This ensures that `semigroupoids` always provides+ `Traversable1` instances for data types from `transformers` and `containers`+ unconditionally.+ 6 [2023.03.12] -------------- * Drop support for GHC 7.10 and earlier.
semigroupoids.cabal view
@@ -1,7 +1,7 @@ cabal-version: 1.24 name: semigroupoids category: Control, Comonads-version: 6+version: 6.0.2 license: BSD2 license-file: LICENSE author: Edward A. Kmett@@ -17,9 +17,13 @@ , GHC == 8.8.4 , GHC == 8.10.7 , GHC == 9.0.2- , GHC == 9.2.7- , GHC == 9.4.4- , GHC == 9.6.1+ , GHC == 9.2.8+ , GHC == 9.4.8+ , GHC == 9.6.7+ , GHC == 9.8.4+ , GHC == 9.10.3+ , GHC == 9.12.2+ , GHC == 9.14.1 build-type: Simple synopsis: Semigroupoids: Category sans id extra-source-files:@@ -64,7 +68,7 @@ source-repository head type: git- location: git://github.com/ekmett/semigroupoids.git+ location: https://github.com/ekmett/semigroupoids.git flag containers description:@@ -85,17 +89,6 @@ default: True manual: True -flag distributive- description:- You can disable the use of the `distributive` package using `-f-distributive`.- .- Disabling this is an unsupported configuration, but it may be useful for accelerating builds in sandboxes for expert users.- .- If disabled we will not supply instances of `Distributive`- .- default: True- manual: True- flag comonad description: You can disable the use of the `comonad` package using `-f-comonad`.@@ -135,15 +128,19 @@ if !impl(ghc >= 9.6) build-depends: foldable1-classes-compat >= 0.1 && < 0.2 + -- On GHC-9.6&base-4.18 we require recent enough transformers and containers+ -- with Foldable1 instances.+ if impl(ghc >= 9.6)+ build-depends: transformers >= 0.6.1.0+ if flag(containers)+ build-depends: containers >= 0.6.7+ if flag(containers)- build-depends: containers >= 0.5.7.1 && < 0.7+ build-depends: containers >= 0.5.7.1 && < 0.9 if flag(contravariant) build-depends: contravariant >= 1.5.3 && < 2 - if flag(distributive)- build-depends: distributive >= 0.5.2 && < 1- if flag(comonad) build-depends: comonad >= 5.0.8 && < 6 @@ -151,7 +148,7 @@ build-depends: tagged >= 0.8.7 && < 1 if flag(unordered-containers)- build-depends: hashable >= 1.2.7.0 && < 1.5,+ build-depends: hashable >= 1.2.7.0 && < 1.6, unordered-containers >= 0.2.8.0 && < 0.3 hs-source-dirs: src@@ -163,9 +160,6 @@ Data.Functor.Bind Data.Functor.Bind.Class Data.Functor.Bind.Trans- Data.Functor.Contravariant.Conclude- Data.Functor.Contravariant.Decide- Data.Functor.Contravariant.Divise Data.Functor.Extend Data.Functor.Plus Data.Groupoid@@ -185,6 +179,12 @@ Semigroupoids.Do other-modules: Semigroupoids.Internal++ if impl(ghc >= 8.6) || flag(contravariant)+ exposed-modules:+ Data.Functor.Contravariant.Conclude+ Data.Functor.Contravariant.Decide+ Data.Functor.Contravariant.Divise ghc-options: -Wall -Wno-warnings-deprecations -Wno-trustworthy-safe
src/Data/Functor/Bind/Class.hs view
@@ -44,6 +44,8 @@ import Control.Arrow import Control.Category import Control.Monad (ap)+import Control.Monad.ST+import qualified Control.Monad.ST.Lazy as Lazy import Control.Monad.Trans.Cont import Control.Monad.Trans.Except import Control.Monad.Trans.Identity@@ -342,6 +344,17 @@ Lazy.WriterT f <.> Lazy.WriterT a = Lazy.WriterT $ flap <$> f <.> a where flap ~(x,m) ~(y,n) = (x y, m <> n) +instance Apply (ST s) where+ (<.>) = (<*>)+ (<.) = (<*)+ (.>) = (*>)++instance Apply (Lazy.ST s) where+ (<.>) = (<*>)+ (<.) = (<*)+ (.>) = (*>)++ #if MIN_VERSION_transformers(0,5,6) -- | @since 5.3.6 instance (Bind m) => Apply (CPS.WriterT w m) where@@ -572,6 +585,12 @@ (>>-) = (>>=) instance Bind IO where+ (>>-) = (>>=)++instance Bind (ST s) where+ (>>-) = (>>=)++instance Bind (Lazy.ST s) where (>>-) = (>>=) instance Bind Maybe where
src/Data/Functor/Contravariant/Conclude.hs view
@@ -12,6 +12,8 @@ -- Stability : provisional -- Portability : portable --+-- This module is only available if building with GHC 8.6 or later, or if the+-- @+contravariant@ @cabal@ build flag is available. ---------------------------------------------------------------------------- module Data.Functor.Contravariant.Conclude ( Conclude(..)@@ -22,7 +24,6 @@ import Control.Applicative.Backwards import Control.Monad.Trans.Identity-import Control.Monad.Trans.Maybe import qualified Control.Monad.Trans.RWS.Lazy as Lazy import qualified Control.Monad.Trans.RWS.Strict as Strict import Control.Monad.Trans.Reader@@ -35,8 +36,6 @@ import Data.Functor.Compose import Data.Functor.Contravariant import Data.Functor.Contravariant.Decide-import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible import Data.Functor.Product import Data.Functor.Reverse import Data.Monoid (Alt(..))@@ -44,8 +43,13 @@ import Data.Void import GHC.Generics -#if !(MIN_VERSION_transformers(0,6,0))+#if defined(MIN_VERSION_contravariant)+# if !(MIN_VERSION_transformers(0,6,0)) import Control.Monad.Trans.List+# endif+import Control.Monad.Trans.Maybe+import Data.Functor.Contravariant.Divise+import Data.Functor.Contravariant.Divisible #endif #ifdef MIN_VERSION_StateVar@@ -110,29 +114,39 @@ gconcluded :: (Generic1 f, Conclude (Rep1 f)) => f Void gconcluded = to1 concluded --- | @since 5.3.6+#if defined(MIN_VERSION_contravariant)+-- | This instance is only available if the @+contravariant@ @cabal@ flag is+-- enabled.+--+-- @since 5.3.6 instance Decidable f => Conclude (WrappedDivisible f) where conclude f = WrapDivisible (lose f)+#endif -- | @since 5.3.6-instance Conclude Comparison where conclude = lose+instance Conclude Comparison where+ conclude f = Comparison $ \a _ -> absurd (f a) -- | @since 5.3.6-instance Conclude Equivalence where conclude = lose+instance Conclude Equivalence where+ conclude f = Equivalence $ absurd . f -- | @since 5.3.6-instance Conclude Predicate where conclude = lose+instance Conclude Predicate where+ conclude f = Predicate $ absurd . f -- | @since 5.3.6 instance Conclude (Op r) where conclude f = Op $ absurd . f -- | @since 5.3.6-instance Conclude Proxy where conclude = lose+instance Conclude Proxy where+ conclude _ = Proxy #ifdef MIN_VERSION_StateVar -- | @since 5.3.6-instance Conclude SettableStateVar where conclude = lose+instance Conclude SettableStateVar where+ conclude k = SettableStateVar (absurd . k) #endif -- | @since 5.3.6@@ -140,7 +154,8 @@ conclude = Alt . conclude -- | @since 5.3.6-instance Conclude U1 where conclude = lose+instance Conclude U1 where+ conclude _ = U1 -- | @since 5.3.6 instance Conclude f => Conclude (Rec1 f) where@@ -178,15 +193,23 @@ instance Conclude m => Conclude (Strict.RWST r w s m) where conclude f = Strict.RWST $ \_ _ -> contramap (\(a, _, _) -> a) (conclude f) -#if !(MIN_VERSION_transformers(0,6,0))--- | @since 5.3.6+#if defined(MIN_VERSION_contravariant)+# if !(MIN_VERSION_transformers(0,6,0))+-- | This instance is only available if the @+contravariant@ @cabal@ flag is+-- enabled.+--+-- @since 5.3.6 instance (Divisible m, Divise m) => Conclude (ListT m) where conclude _ = ListT conquer-#endif+# endif --- | @since 5.3.6+-- | This instance is only available if the @+contravariant@ @cabal@ flag is+-- enabled.+--+-- @since 5.3.6 instance (Divisible m, Divise m) => Conclude (MaybeT m) where conclude _ = MaybeT conquer+#endif -- | @since 5.3.6 instance Conclude m => Conclude (Lazy.StateT s m) where
src/Data/Functor/Contravariant/Decide.hs view
@@ -14,6 +14,8 @@ -- Stability : provisional -- Portability : portable --+-- This module is only available if building with GHC 8.6 or later, or if the+-- @+contravariant@ @cabal@ build flag is available. ---------------------------------------------------------------------------- module Data.Functor.Contravariant.Decide ( Decide(..)@@ -37,7 +39,6 @@ import Data.Functor.Compose import Data.Functor.Contravariant import Data.Functor.Contravariant.Divise-import Data.Functor.Contravariant.Divisible import Data.Functor.Product import Data.Functor.Reverse import Data.Monoid (Alt(..))@@ -50,6 +51,10 @@ import Data.Either #endif +#if defined(MIN_VERSION_contravariant)+import Data.Functor.Contravariant.Divisible+#endif+ #ifdef MIN_VERSION_StateVar import Data.StateVar #endif@@ -99,18 +104,38 @@ gdecided :: (Generic1 f, Decide (Rep1 f)) => f b -> f c -> f (Either b c) gdecided fb fc = gdecide id fb fc --- | @since 5.3.6+#if defined(MIN_VERSION_contravariant)+-- | This instance is only available if the @+contravariant@ @cabal@ flag is+-- enabled.+--+-- @since 5.3.6 instance Decidable f => Decide (WrappedDivisible f) where decide f (WrapDivisible x) (WrapDivisible y) = WrapDivisible (choose f x y)+#endif -- | @since 5.3.6-instance Decide Comparison where decide = choose+instance Decide Comparison where+ decide f (Comparison g) (Comparison h) = Comparison $ \a b -> case f a of+ Left c -> case f b of+ Left d -> g c d+ Right{} -> LT+ Right c -> case f b of+ Left{} -> GT+ Right d -> h c d -- | @since 5.3.6-instance Decide Equivalence where decide = choose+instance Decide Equivalence where+ decide f (Equivalence g) (Equivalence h) = Equivalence $ \a b -> case f a of+ Left c -> case f b of+ Left d -> g c d+ Right{} -> False+ Right c -> case f b of+ Left{} -> False+ Right d -> h c d -- | @since 5.3.6-instance Decide Predicate where decide = choose+instance Decide Predicate where+ decide f (Predicate g) (Predicate h) = Predicate $ either g h . f -- | Unlike 'Decidable', requires no constraint on @r@. --@@ -123,7 +148,8 @@ decide f (Alt l) (Alt r) = Alt $ decide f l r -- | @since 5.3.6-instance Decide U1 where decide = choose+instance Decide U1 where+ decide _ U1 U1 = U1 -- | Has no 'Decidable' or 'Conclude' instance. --
src/Data/Functor/Contravariant/Divise.hs view
@@ -14,6 +14,8 @@ -- Stability : provisional -- Portability : portable --+-- This module is only available if building with GHC 8.6 or later, or if the+-- @+contravariant@ @cabal@ build flag is available. ---------------------------------------------------------------------------- module Data.Functor.Contravariant.Divise ( Divise(..)@@ -41,7 +43,6 @@ import Data.Functor.Compose import Data.Functor.Constant import Data.Functor.Contravariant-import Data.Functor.Contravariant.Divisible import Data.Functor.Product import Data.Functor.Reverse import Data.Monoid (Alt(..))@@ -57,6 +58,10 @@ import Data.Semigroup (Semigroup(..)) #endif +#if defined(MIN_VERSION_contravariant)+import Data.Functor.Contravariant.Divisible+#endif+ #ifdef MIN_VERSION_StateVar import Data.StateVar #endif@@ -127,9 +132,14 @@ instance Contravariant f => Contravariant (WrappedDivisible f) where contramap f (WrapDivisible a) = WrapDivisible (contramap f a) --- | @since 5.3.6+#if defined(MIN_VERSION_contravariant)+-- | This instance is only available if the @+contravariant@ @cabal@ flag is+-- enabled.+--+-- @since 5.3.6 instance Divisible f => Divise (WrappedDivisible f) where divise f (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divide f x y)+#endif -- | Unlike 'Divisible', requires only 'Semigroup' on @r@. --@@ -151,20 +161,31 @@ divise _ (Constant a) (Constant b) = Constant (a <> b) -- | @since 5.3.6-instance Divise Comparison where divise = divide+instance Divise Comparison where+ divise f (Comparison g) (Comparison h) = Comparison $ \a b -> case f a of+ (a',a'') -> case f b of+ (b',b'') -> g a' b' `mappend` h a'' b'' -- | @since 5.3.6-instance Divise Equivalence where divise = divide+instance Divise Equivalence where+ divise f (Equivalence g) (Equivalence h) = Equivalence $ \a b -> case f a of+ (a',a'') -> case f b of+ (b',b'') -> g a' b' && h a'' b'' -- | @since 5.3.6-instance Divise Predicate where divise = divide+instance Divise Predicate where+ divise f (Predicate g) (Predicate h) = Predicate $ \a -> case f a of+ (b, c) -> g b && h c -- | @since 5.3.6-instance Divise Proxy where divise = divide+instance Divise Proxy where+ divise _ Proxy Proxy = Proxy #ifdef MIN_VERSION_StateVar -- | @since 5.3.6-instance Divise SettableStateVar where divise = divide+instance Divise SettableStateVar where+ divise k (SettableStateVar l) (SettableStateVar r) = SettableStateVar $ \ a -> case k a of+ (b, c) -> l b >> r c #endif -- | @since 5.3.6@@ -172,7 +193,8 @@ divise f (Alt l) (Alt r) = Alt $ divise f l r -- | @since 5.3.6-instance Divise U1 where divise = divide+instance Divise U1 where+ divise _ U1 U1 = U1 -- | Has no 'Divisible' instance. --
src/Data/Semigroup/Foldable.hs view
@@ -107,7 +107,7 @@ -- | Generic 'fold1'. Caveats: -- -- 1. Will not compile if @t@ is an empty constructor.--- 2. Will not compile if @t@ has some fields that don't mention @a@, for exmaple @data Bar a = MkBar a Int@+-- 2. Will not compile if @t@ has some fields that don't mention @a@, for example @data Bar a = MkBar a Int@ -- -- @since 5.3.8 gfold1 :: (Foldable1 (Rep1 t), Generic1 t, Semigroup m) => t m -> m
src/Data/Semigroup/Traversable.hs view
@@ -37,7 +37,7 @@ -- | Generic 'traverse1'. Caveats: -- -- 1. Will not compile if @t@ is an empty constructor.--- 2. Will not compile if @t@ has some fields that don't mention @a@, for exmaple @data Bar a = MkBar a Int@+-- 2. Will not compile if @t@ has some fields that don't mention @a@, for example @data Bar a = MkBar a Int@ -- -- @since 5.3.8 gtraverse1 ::
src/Data/Semigroup/Traversable/Class.hs view
@@ -1,22 +1,7 @@ {-# LANGUAGE CPP, TypeOperators #-} {-# LANGUAGE Trustworthy #-} -#ifdef MIN_VERSION_containers-# if MIN_VERSION_base(4,18,0)-# define HAS_FOLDABLE1_CONTAINERS MIN_VERSION_containers(0,6,7)-# else-# define HAS_FOLDABLE1_CONTAINERS 1-# endif-#else-# define HAS_FOLDABLE1_CONTAINERS 0-#endif -#if MIN_VERSION_base(4,18,0)-# define HAS_FOLDABLE1_TRANSFORMERS MIN_VERSION_transformers(0,6,1)-#else-# define HAS_FOLDABLE1_TRANSFORMERS 1-#endif- ----------------------------------------------------------------------------- -- | -- Copyright : (C) 2011-2015 Edward Kmett@@ -62,16 +47,14 @@ import Data.Traversable.Instances () import GHC.Generics -#if HAS_FOLDABLE1_CONTAINERS+#ifdef MIN_VERSION_containers import Data.Tree #endif -#if HAS_FOLDABLE1_TRANSFORMERS import Control.Applicative.Backwards import Control.Applicative.Lift import Control.Monad.Trans.Identity import Data.Functor.Reverse-#endif class (Bifoldable1 t, Bitraversable t) => Bitraversable1 t where bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> t a c -> f (t b d)@@ -197,7 +180,6 @@ instance (Traversable1 f, Traversable1 g) => Traversable1 (Compose f g) where traverse1 f = fmap Compose . traverse1 (traverse1 f) . getCompose -#if HAS_FOLDABLE1_TRANSFORMERS instance Traversable1 f => Traversable1 (IdentityT f) where traverse1 f = fmap IdentityT . traverse1 f . runIdentityT @@ -210,7 +192,6 @@ instance Traversable1 f => Traversable1 (Reverse f) where traverse1 f = fmap Reverse . forwards . traverse1 (Backwards . f) . getReverse-#endif instance Traversable1 Complex where traverse1 f (a :+ b) = (:+) <$> f a <.> f b@@ -221,7 +202,7 @@ traverse1 f (Tagged a) = Tagged <$> f a #endif -#if HAS_FOLDABLE1_CONTAINERS+#ifdef MIN_VERSION_containers instance Traversable1 Tree where traverse1 f (Node a []) = (`Node`[]) <$> f a traverse1 f (Node a (x:xs)) = (\b (y:|ys) -> Node b (y:ys)) <$> f a <.> traverse1 (traverse1 f) (x :| xs)
src/Data/Semigroupoid/Categorical.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE Trustworthy #-}@@ -22,6 +23,9 @@ import Control.Category (Category (id, (.))) import Data.Semigroupoid (Semigroupoid (o))+#if __GLASGOW_HASKELL__ >= 904+import Data.Type.Equality (type (~))+#endif import Prelude () -- | Attaches an identity.