semigroupoids 4.0.2.1 → 4.0.3
raw patch · 13 files changed
+221/−47 lines, 13 files
Files
- semigroupoids.cabal +55/−5
- src/Data/Functor/Alt.hs +8/−3
- src/Data/Functor/Bind.hs +29/−10
- src/Data/Functor/Extend.hs +15/−4
- src/Data/Functor/Plus.hs +7/−2
- src/Data/Semifunctor.hs +18/−7
- src/Data/Semifunctor/Associative.hs +10/−2
- src/Data/Semifunctor/Braided.hs +16/−5
- src/Data/Semigroup/Foldable.hs +13/−2
- src/Data/Semigroup/Traversable.hs +12/−1
- src/Data/Semigroupoid.hs +17/−3
- src/Data/Semigroupoid/Ob.hs +11/−2
- src/Data/Semigroupoid/Static.hs +10/−1
semigroupoids.cabal view
@@ -1,6 +1,6 @@ name: semigroupoids category: Control, Comonads-version: 4.0.2.1+version: 4.0.3 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -54,15 +54,65 @@ type: git location: git://github.com/ekmett/semigroupoids.git +flag containers+ description:+ You can disable the use of the `containers` package using `-f-containers`.+ .+ Disabing this is an unsupported configuration, but it may be useful for accelerating builds in sandboxes for expert users.+ default: True+ manual: True++flag contravariant+ description:+ You can disable the use of the `contravariant` package using `-f-contravariant`.+ .+ 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 `Contravariant`+ .+ 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`.+ .+ 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 `Comonad`+ .+ default: True+ manual: True++ library build-depends: base >= 4 && < 5,- containers >= 0.3 && < 0.6,- contravariant >= 0.2.0.1 && < 1,- comonad >= 4 && < 5,- distributive >= 0.2.2 && < 1, semigroups >= 0.8.3.1 && < 1, transformers >= 0.2 && < 0.6++ if flag(containers)+ build-depends: containers >= 0.3 && < 0.6++ if flag(contravariant)+ build-depends: contravariant >= 0.2.0.1 && < 1++ if flag(distributive)+ build-depends: distributive >= 0.2.2 && < 1++ if flag(comonad)+ build-depends: comonad >= 4 && < 5 hs-source-dirs: src
src/Data/Functor/Alt.hs view
@@ -35,14 +35,17 @@ import qualified Control.Monad.Trans.Writer.Lazy as Lazy import Data.Functor.Apply import Data.Functor.Bind-import qualified Data.IntMap as IntMap-import Data.IntMap (IntMap) import Data.Semigroup import Data.List.NonEmpty (NonEmpty(..))+import Prelude (($),Either(..),Maybe(..),const,IO,Ord,(++))++#ifdef MIN_VERSION_containers+import qualified Data.IntMap as IntMap+import Data.IntMap (IntMap) import Data.Sequence (Seq) import qualified Data.Map as Map import Data.Map (Map)-import Prelude (($),Either(..),Maybe(..),const,IO,Ord,(++))+#endif infixl 3 <!> @@ -116,6 +119,7 @@ instance ArrowPlus a => Alt (WrappedArrow a b) where (<!>) = (<|>) +#ifdef MIN_VERSION_containers instance Ord k => Alt (Map k) where (<!>) = Map.union @@ -124,6 +128,7 @@ instance Alt Seq where (<!>) = mappend+#endif instance Alt NonEmpty where (a :| as) <!> ~(b :| bs) = a :| (as ++ b : bs)
src/Data/Functor/Bind.hs view
@@ -1,15 +1,16 @@ {-# LANGUAGE CPP #-}-#ifndef MIN_VERSION_comonad-#define MIN_VERSION_comonad(x,y,z) 1-#endif #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#ifdef MIN_VERSION_comonad #if __GLASGOW_HASKELL__ >= 707 && (MIN_VERSION_comonad(3,0,3)) {-# LANGUAGE Safe #-} #else {-# LANGUAGE Trustworthy #-} #endif+#else+{-# LANGUAGE Trustworthy #-} #endif+#endif {-# OPTIONS_GHC -fno-warn-orphans #-} ----------------------------------------------------------------------------- -- |@@ -51,10 +52,6 @@ import Control.Applicative import Control.Arrow import Control.Category-import Control.Comonad-import Control.Comonad.Trans.Env-import Control.Comonad.Trans.Store-import Control.Comonad.Trans.Traced import Control.Monad (ap) #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 707 import Control.Monad.Instances ()@@ -75,16 +72,30 @@ import Data.Functor.Identity import Data.Functor.Product import Data.Functor.Extend+import Data.List.NonEmpty+import Data.Semigroup hiding (Product)+import Prelude hiding (id, (.))+++#ifdef MIN_VERSION_containers import qualified Data.IntMap as IntMap import Data.IntMap (IntMap) import qualified Data.Map as Map import Data.Map (Map)-import Data.List.NonEmpty-import Data.Semigroup hiding (Product) import Data.Sequence (Seq) import Data.Tree (Tree)-import Prelude hiding (id, (.))+#endif +#ifdef MIN_VERSION_comonad+import Control.Comonad+import Control.Comonad.Trans.Env+import Control.Comonad.Trans.Store+import Control.Comonad.Trans.Traced+#else+($>) :: Functor f => f a -> b -> f b+($>) = flip (<$)+#endif+ infixl 1 >>- infixr 1 -<< infixl 4 <.>, <., .>, <..>@@ -186,6 +197,7 @@ (<. ) = (<* ) ( .>) = ( *>) +#ifdef MIN_VERSION_containers -- | A Map is not 'Applicative', but it is an instance of 'Apply' instance Ord k => Apply (Map k) where (<.>) = Map.intersectionWith id@@ -205,6 +217,7 @@ (<.>) = (<*>) (<. ) = (<* ) ( .>) = ( *>)+#endif -- MaybeT is _not_ the same as Compose f Maybe instance (Bind m, Monad m) => Apply (MaybeT m) where@@ -244,6 +257,7 @@ instance Apply (ContT r m) where ContT f <.> ContT v = ContT $ \k -> f $ \g -> v (k . g) +#ifdef MIN_VERSION_comonad instance (Semigroup e, Apply w) => Apply (EnvT e w) where EnvT ef wf <.> EnvT ea wa = EnvT (ef <> ea) (wf <.> wa) @@ -252,6 +266,7 @@ instance Apply w => Apply (TracedT m w) where TracedT wf <.> TracedT wa = TracedT (ap <$> wf <.> wa)+#endif -- | Wrap an 'Applicative' to be used as a member of 'Apply' newtype WrappedApplicative f a = WrapApplicative { unwrapApplicative :: f a }@@ -320,6 +335,7 @@ duplicated w@(MaybeApply Right{}) = MaybeApply (Right w) duplicated (MaybeApply (Left fa)) = MaybeApply (Left (extended (MaybeApply . Left) fa)) +#ifdef MIN_VERSION_comonad instance Comonad f => Comonad (MaybeApply f) where duplicate w@(MaybeApply Right{}) = MaybeApply (Right w) duplicate (MaybeApply (Left fa)) = MaybeApply (Left (extend (MaybeApply . Left) fa))@@ -328,6 +344,7 @@ instance Apply (Cokleisli w a) where Cokleisli f <.> Cokleisli a = Cokleisli (\w -> (f w) (a w))+#endif -- | A 'Monad' sans 'return'. --@@ -471,6 +488,7 @@ (>>-) = (>>=) -} +#ifdef MIN_VERSION_containers -- | A 'Map' is not a 'Monad', but it is an instance of 'Bind' instance Ord k => Bind (Map k) where m >>- f = Map.mapMaybeWithKey (\k -> Map.lookup k . f) m@@ -484,3 +502,4 @@ instance Bind Tree where (>>-) = (>>=)+#endif
src/Data/Functor/Extend.hs view
@@ -21,19 +21,26 @@ import Prelude hiding (id, (.)) import Control.Category-import Control.Comonad.Trans.Env-import Control.Comonad.Trans.Store-import Control.Comonad.Trans.Traced import Control.Monad.Trans.Identity-import Data.Functor.Coproduct import Data.Functor.Identity import Data.Semigroup import Data.List (tails) import Data.List.NonEmpty (NonEmpty(..), toList)++#ifdef MIN_VERSION_containers import Data.Sequence (Seq) import qualified Data.Sequence as Seq import Data.Tree+#endif ++#ifdef MIN_VERSION_comonad+import Data.Functor.Coproduct+import Control.Comonad.Trans.Env+import Control.Comonad.Trans.Store+import Control.Comonad.Trans.Traced+#endif+ class Functor w => Extend w where -- | -- > duplicated = extended id@@ -74,12 +81,15 @@ instance Semigroup m => Extend ((->)m) where duplicated f m = f . (<>) m +#ifdef MIN_VERSION_containers instance Extend Seq where duplicated l = Seq.take (Seq.length l) (Seq.tails l) instance Extend Tree where duplicated w@(Node _ as) = Node w (map duplicated as)+#endif +#ifdef MIN_VERSION_comonad instance (Extend f, Extend g) => Extend (Coproduct f g) where extended f = Coproduct . coproduct (Left . extended (f . Coproduct . Left))@@ -94,6 +104,7 @@ instance (Extend w, Semigroup m) => Extend (TracedT m w) where extended f = TracedT . extended (\wf m -> f (TracedT (fmap (. (<>) m) wf))) . runTracedT+#endif -- I can't fix the world -- instance (Monoid m, Extend n) => Extend (ReaderT m n)
src/Data/Functor/Plus.hs view
@@ -37,13 +37,16 @@ import Data.Functor.Apply import Data.Functor.Alt import Data.Functor.Bind+import Data.Semigroup+import Prelude hiding (id, (.))++#ifdef MIN_VERSION_containers import qualified Data.IntMap as IntMap import Data.IntMap (IntMap)-import Data.Semigroup import Data.Sequence (Seq) import qualified Data.Map as Map import Data.Map (Map)-import Prelude hiding (id, (.))+#endif -- | Laws: --@@ -73,6 +76,7 @@ instance ArrowPlus a => Plus (WrappedArrow a b) where zero = empty +#ifdef MIN_VERSION_containers instance Ord k => Plus (Map k) where zero = Map.empty @@ -81,6 +85,7 @@ instance Plus Seq where zero = mempty+#endif instance Alternative f => Plus (WrappedApplicative f) where zero = empty
src/Data/Semifunctor.hs view
@@ -7,17 +7,17 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE CPP #-} -#ifndef MIN_VERSION_comonad-#define MIN_VERSION_comonad(x,y,z) 1-#endif- #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#ifdef MIN_VERSION_comonad #if MIN_VERSION_comonad(3,0,3) {-# LANGUAGE Safe #-} #else {-# LANGUAGE Trustworthy #-} #endif+#else+{-# LANGUAGE Trustworthy #-} #endif+#endif module Data.Semifunctor ( Semifunctor(..)@@ -38,11 +38,8 @@ import Control.Arrow hiding (first, second, left, right) import Control.Category-import Control.Comonad import Control.Monad (liftM)-import Data.Distributive import Data.Functor.Bind-import Data.Functor.Extend import Data.Traversable import Data.Semigroup.Traversable import Data.Semigroupoid@@ -51,6 +48,14 @@ import Data.Semigroupoid.Product import Prelude hiding ((.),id, mapM) +#ifdef MIN_VERSION_comonad+import Control.Comonad+import Data.Functor.Extend+#ifdef MIN_VERSION_distributive+import Data.Distributive+#endif+#endif+ -- | Semifunctors map objects to objects, and arrows to arrows preserving connectivity -- as normal functors, but do not purport to preserve identity arrows. We apply them -- to semigroupoids, because those don't even claim to offer identity arrows!@@ -65,8 +70,10 @@ instance (Traversable f, Bind m, Monad m) => Semifunctor (WrappedFunctor f) (Kleisli m) (Kleisli m) where semimap (Kleisli f) = Kleisli $ liftM WrapFunctor . mapM f . unwrapFunctor +#if defined(MIN_VERSION_distributive) && defined(MIN_VERSION_comonad) instance (Distributive f, Extend w) => Semifunctor (WrappedFunctor f) (Cokleisli w) (Cokleisli w) where semimap (Cokleisli w) = Cokleisli $ WrapFunctor . cotraverse w . fmap unwrapFunctor+#endif data WrappedTraversable1 f a = WrapTraversable1 { unwrapTraversable1 :: f a } @@ -83,11 +90,13 @@ (#) :: a -> b -> Bi (,) (a,b) a # b = Bi (a,b) +#ifdef MIN_VERSION_comonad fstP :: Bi (,) (a, b) -> a fstP (Bi (a,_)) = a sndP :: Bi (,) (a, b) -> b sndP (Bi (_,b)) = b+#endif left :: a -> Bi Either (a,b) left = Bi . Left@@ -111,10 +120,12 @@ lr l _ (Bi (Left a)) = left <$> l a lr _ r (Bi (Right b)) = right <$> r b +#ifdef MIN_VERSION_comonad instance Extend w => Semifunctor (Bi (,)) (Product (Cokleisli w) (Cokleisli w)) (Cokleisli w) where semimap (Pair l r) = Cokleisli $ \p -> runCokleisli l (fstP <$> p) # runCokleisli r (sndP <$> p) -- instance Extend w => Semifunctor (Bi Either)) (Product (Cokleisli w) (Cokleisli w)) (Cokleisli w) where+#endif semibimap :: Semifunctor p (Product l r) cod => l a b -> r c d -> cod (p (a,c)) (p (b,d)) semibimap f g = semimap (Pair f g)
src/Data/Semifunctor/Associative.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Semifunctor.Associative@@ -17,12 +18,15 @@ import Prelude hiding ((.), id) import Control.Arrow-import Control.Comonad import Data.Functor.Bind-import Data.Functor.Extend import Data.Semifunctor -- import Data.Isomorphism +#ifdef MIN_VERSION_comonad+import Data.Functor.Extend+import Control.Comonad+#endif+ class Semifunctor p (Product k k) k => Associative k p where associate :: k (p(p(a,b),c)) (p(a,p(b,c))) @@ -43,6 +47,7 @@ instance (Bind m, Monad m) => Associative (Kleisli m) (Bi (,)) where associate = kleisliAssociate +#ifdef MIN_VERSION_comonad cokleisliAssociate :: (Comonad m, Semifunctor p (Product (Cokleisli m) (Cokleisli m)) (Cokleisli m), Associative (->) p) => Cokleisli m (p(p(a,b),c)) (p(a,p(b,c))) cokleisliAssociate = Cokleisli (associate . extract) @@ -50,6 +55,7 @@ associate = cokleisliAssociate -- instance Comonad m => Associative (Cokleisli m) (Bi Either) where associate = cokleisliAssociate+#endif -- instance Disassociative k p => Associative (Dual k) p -- instance (Monad m, Semifunctor p (Product (Kleisli m) (Kleisli m) (Kleisli m), Associative (->) p) => Associative (Kleisli m) p) where associate = kleisliAssociate@@ -74,11 +80,13 @@ instance (Bind m, Monad m) => Disassociative (Kleisli m) (Bi (,)) where disassociate = kleisliDisassociate +#ifdef MIN_VERSION_comonad cokleisliDisassociate :: (Comonad m, Semifunctor p (Product (Cokleisli m) (Cokleisli m)) (Cokleisli m), Disassociative (->) p) => Cokleisli m (p(a,p(b,c))) (p(p(a,b),c)) cokleisliDisassociate = Cokleisli (disassociate . extract) instance (Extend m, Comonad m) => Disassociative (Cokleisli m) (Bi (,)) where disassociate = cokleisliDisassociate+#endif -- instance Associative k p => Disassociative (Dual k) p
src/Data/Semifunctor/Braided.hs view
@@ -3,17 +3,19 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-}-#ifndef MIN_VERSION_comonad-#define MIN_VERSION_comonad(x,y,z) 1-#endif #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#ifdef MIN_VERSION_comonad #if MIN_VERSION_comonad(3,0,3) {-# LANGUAGE Safe #-} #else {-# LANGUAGE Trustworthy #-} #endif+#else+{-# LANGUAGE Trustworthy #-} #endif+#endif+ ----------------------------------------------------------------------------- -- | -- Module : Data.Semifunctor.Braided@@ -28,20 +30,25 @@ module Data.Semifunctor.Braided ( Braided(..) , kleisliBraid+#ifdef MIN_VERSION_comonad , cokleisliBraid+#endif , Symmetric , swap ) where import Prelude hiding ((.), id) import Control.Arrow-import Control.Comonad import Data.Functor.Bind-import Data.Functor.Extend import Data.Semifunctor import Data.Semifunctor.Associative -- import Data.Semigroupoid.Dual +#ifdef MIN_VERSION_comonad+import Control.Comonad+import Data.Functor.Extend+#endif+ class Associative k p => Braided k p where braid :: k (p(a,b)) (p(b,a)) @@ -63,6 +70,7 @@ instance (Bind m, Monad m) => Braided (Kleisli m) (Bi (,)) where braid = kleisliBraid +#ifdef MIN_VERSION_comonad cokleisliBraid :: (Extend w, Comonad w, Semifunctor p (Product (Cokleisli w) (Cokleisli w)) (Cokleisli w), Braided (->) p) => Cokleisli w (p(a,b)) (p(b,a)) cokleisliBraid = Cokleisli (braid . extract)@@ -71,14 +79,17 @@ braid = cokleisliBraid -- instance Comonad w => Braided (Cokleisli w) (Bi Either) where braid = cokleisliBraid+#endif class Braided k p => Symmetric k p instance Symmetric (->) (Bi Either) instance Symmetric (->) (Bi (,)) instance (Bind m, Monad m) => Symmetric (Kleisli m) (Bi Either) instance (Bind m, Monad m) => Symmetric (Kleisli m) (Bi (,))+#ifdef MIN_VERSION_comonad instance (Extend w, Comonad w) => Symmetric (Cokleisli w) (Bi (,)) -- instance Comonad w => Symmetric (Cokleisli w) (Bi Either)+#endif swap :: Symmetric k p => k (p(a,b)) (p(b,a)) swap = braid
src/Data/Semigroup/Foldable.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Semigroup.Foldable@@ -23,13 +24,19 @@ import Data.Functor.Apply import Data.Functor.Product import Data.Functor.Compose-import Data.Functor.Coproduct-import Data.Tree import Data.List.NonEmpty (NonEmpty(..)) import Data.Traversable.Instances () import Data.Semigroup hiding (Product) import Prelude hiding (foldr) +#ifdef MIN_VERSION_containers+import Data.Tree+#endif++#ifdef MIN_VERSION_comonad+import Data.Functor.Coproduct+#endif+ class Foldable t => Foldable1 t where fold1 :: Semigroup m => t m -> m foldMap1 :: Semigroup m => (a -> m) -> t a -> m@@ -37,9 +44,11 @@ foldMap1 f = maybe (error "foldMap1") id . getOption . foldMap (Option . Just . f) fold1 = foldMap1 id +#ifdef MIN_VERSION_containers instance Foldable1 Tree where foldMap1 f (Node a []) = f a foldMap1 f (Node a (x:xs)) = f a <> foldMap1 (foldMap1 f) (x :| xs)+#endif instance Foldable1 Identity where foldMap1 f = f . runIdentity@@ -53,8 +62,10 @@ instance (Foldable1 f, Foldable1 g) => Foldable1 (Product f g) where foldMap1 f (Pair a b) = foldMap1 f a <> foldMap1 f b +#ifdef MIN_VERSION_comonad instance (Foldable1 f, Foldable1 g) => Foldable1 (Coproduct f g) where foldMap1 f = coproduct (foldMap1 f) (foldMap1 f)+#endif instance Foldable1 NonEmpty where foldMap1 f (a :| []) = f a
src/Data/Semigroup/Traversable.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Semigroup.Traversable@@ -18,7 +19,6 @@ import Control.Monad.Trans.Identity import Data.Functor.Apply import Data.Functor.Compose-import Data.Functor.Coproduct import Data.Functor.Identity import Data.Functor.Product import Data.List.NonEmpty (NonEmpty(..))@@ -26,8 +26,15 @@ import Data.Semigroup.Foldable import Data.Traversable import Data.Traversable.Instances ()++#ifdef MIN_VERSION_containers import Data.Tree+#endif +#ifdef MIN_VERSION_comonad+import Data.Functor.Coproduct+#endif+ class (Foldable1 t, Traversable t) => Traversable1 t where traverse1 :: Apply f => (a -> f b) -> t a -> f (t b) sequence1 :: Apply f => t (f b) -> f (t b)@@ -50,14 +57,18 @@ instance (Traversable1 f, Traversable1 g) => Traversable1 (Product f g) where traverse1 f (Pair a b) = Pair <$> traverse1 f a <.> traverse1 f b +#ifdef MIN_VERSION_comonad instance (Traversable1 f, Traversable1 g) => Traversable1 (Coproduct f g) where traverse1 f = coproduct (fmap (Coproduct . Left) . traverse1 f) (fmap (Coproduct . Right) . traverse1 f)+#endif +#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)+#endif instance Traversable1 NonEmpty where traverse1 f (a :| []) = (:|[]) <$> f a
src/Data/Semigroupoid.hs view
@@ -1,11 +1,15 @@ {-# LANGUAGE CPP #-} #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#ifdef MIN_VERSION_comonad #if __GLASGOW_HASKELL__ >= 707 && (MIN_VERSION_comonad(3,0,3)) {-# LANGUAGE Safe #-} #else {-# LANGUAGE Trustworthy #-} #endif+#else+{-# LANGUAGE Trustworthy #-} #endif+#endif -----------------------------------------------------------------------------@@ -29,13 +33,19 @@ import Control.Arrow import Data.Functor.Bind-import Data.Functor.Extend-import Data.Functor.Contravariant-import Control.Comonad import Data.Semigroup import Control.Category import Prelude hiding (id, (.)) +#ifdef MIN_VERSION_contravariant+import Data.Functor.Contravariant+#endif++#ifdef MIN_VERSION_comonad+import Data.Functor.Extend+import Control.Comonad+#endif+ -- | 'Control.Category.Category' sans 'Control.Category.id' class Semigroupoid c where o :: c j k -> c i j -> c i k@@ -50,11 +60,15 @@ instance Bind m => Semigroupoid (Kleisli m) where Kleisli g `o` Kleisli f = Kleisli $ \a -> f a >>- g +#ifdef MIN_VERSION_comonad instance Extend w => Semigroupoid (Cokleisli w) where Cokleisli f `o` Cokleisli g = Cokleisli $ f . extended g+#endif +#ifdef MIN_VERSION_contravariant instance Semigroupoid Op where Op f `o` Op g = Op (g `o` f)+#endif newtype WrappedCategory k a b = WrapCategory { unwrapCategory :: k a b }
src/Data/Semigroupoid/Ob.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE CPP #-}+ ----------------------------------------------------------------------------- -- | -- Module : Data.Semigroup.Ob@@ -17,11 +19,15 @@ import Data.Semigroupoid import Data.Semigroupoid.Product import Data.Semigroupoid.Coproduct-import Control.Comonad import Data.Functor.Bind-import Data.Functor.Extend import Control.Arrow ++#ifdef MIN_VERSION_comonad+import Data.Functor.Extend+import Control.Comonad+#endif+ class Semigroupoid k => Ob k a where semiid :: k a a @@ -37,8 +43,11 @@ instance (Bind m, Monad m) => Ob (Kleisli m) a where semiid = Kleisli return ++#ifdef MIN_VERSION_comonad instance (Extend w, Comonad w) => Ob (Cokleisli w) a where semiid = Cokleisli extract+#endif instance Ob (->) a where semiid = id
src/Data/Semigroupoid/Static.hs view
@@ -1,11 +1,15 @@ {-# LANGUAGE CPP #-} #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+#ifdef MIN_VERSION_comonad #if __GLASGOW_HASKELL__ >= 707 && (MIN_VERSION_comonad(3,0,3)) {-# LANGUAGE Safe #-} #else {-# LANGUAGE Trustworthy #-} #endif+#else+{-# LANGUAGE Trustworthy #-} #endif+#endif module Data.Semigroupoid.Static ( Static(..)@@ -14,7 +18,6 @@ import Control.Arrow import Control.Applicative import Control.Category-import Control.Comonad #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 707 import Control.Monad.Instances () #endif@@ -30,6 +33,10 @@ import Data.Typeable #endif +#ifdef MIN_VERSION_comonad+import Control.Comonad+#endif+ newtype Static f a b = Static { runStatic :: f (a -> b) } #ifdef LANGUAGE_DeriveDataTypeable deriving (Typeable)@@ -54,9 +61,11 @@ instance (Extend f, Semigroup a) => Extend (Static f a) where extended f = Static . extended (\wf m -> f (Static (fmap (. (<>) m) wf))) . runStatic +#ifdef MIN_VERSION_comonad instance (Comonad f, Monoid a) => Comonad (Static f a) where extend f = Static . extend (\wf m -> f (Static (fmap (. mappend m) wf))) . runStatic extract (Static g) = extract g mempty+#endif instance Apply f => Semigroupoid (Static f) where Static f `o` Static g = Static ((.) <$> f <.> g)