semigroupoids (empty) → 1.0.0
raw patch · 15 files changed
+1325/−0 lines, 15 filesdep +basedep +bifunctorsdep +comonadsetup-changed
Dependencies added: base, bifunctors, comonad, containers, contravariant, semigroups, transformers
Files
- Control/Arrow/Static.hs +73/−0
- Data/Bifunctor/Apply.hs +62/−0
- Data/Functor/Alt.hs +166/−0
- Data/Functor/Apply.hs +30/−0
- Data/Functor/Bind.hs +460/−0
- Data/Functor/Bind/Trans.hs +66/−0
- Data/Functor/Plus.hs +116/−0
- Data/Semigroup/Bifoldable.hs +68/−0
- Data/Semigroup/Bitraversable.hs +39/−0
- Data/Semigroup/Foldable.hs +61/−0
- Data/Semigroup/Traversable.hs +31/−0
- Data/Semigroupoid.hs +35/−0
- LICENSE +30/−0
- Setup.lhs +7/−0
- semigroupoids.cabal +81/−0
+ Control/Arrow/Static.hs view
@@ -0,0 +1,73 @@+{-# LANGUAGE CPP #-}+module Control.Arrow.Static where++import Control.Arrow+import Control.Applicative+import Control.Category+import Control.Comonad+import Control.Monad.Instances+import Control.Monad (ap)+import Data.Functor.Apply+import Data.Functor.Plus+import Data.Monoid+import Data.Semigroup+import Data.Semigroupoid+import Prelude hiding ((.), id)++#ifdef LANGUAGE_DeriveDataTypeable +import Data.Typeable+#endif++newtype Static f a b = Static { runStatic :: f (a -> b) } +#ifdef LANGUAGE_DeriveDataTypeable+ deriving (Typeable)+#endif++instance Functor f => Functor (Static f a) where+ fmap f = Static . fmap (f .) . runStatic++instance Apply f => Apply (Static f a) where+ Static f <.> Static g = Static (ap <$> f <.> g)++instance Alt f => Alt (Static f a) where+ Static f <!> Static g = Static (f <!> g)++instance Plus f => Plus (Static f a) where+ zero = Static zero++instance Applicative f => Applicative (Static f a) where+ pure = Static . pure . const + Static f <*> Static g = Static (ap <$> f <*> g)++instance (Extend f, Semigroup a) => Extend (Static f a) where+ extend f = Static . extend (\wf m -> f (Static (fmap (. (<>) m) wf))) . runStatic++instance (Comonad f, Semigroup a, Monoid a) => Comonad (Static f a) where+ extract (Static g) = extract g mempty++instance Apply f => Semigroupoid (Static f) where+ Static f `o` Static g = Static ((.) <$> f <.> g)++instance Applicative f => Category (Static f) where+ id = Static (pure id)+ Static f . Static g = Static ((.) <$> f <*> g)++instance Applicative f => Arrow (Static f) where+ arr = Static . pure + first (Static g) = Static (first <$> g) + second (Static g) = Static (second <$> g) + Static g *** Static h = Static ((***) <$> g <*> h)+ Static g &&& Static h = Static ((&&&) <$> g <*> h)++instance Alternative f => ArrowZero (Static f) where+ zeroArrow = Static empty+ +instance Alternative f => ArrowPlus (Static f) where+ Static f <+> Static g = Static (f <|> g)++instance Applicative f => ArrowChoice (Static f) where+ left (Static g) = Static (left <$> g)+ right (Static g) = Static (right <$> g)+ Static g +++ Static h = Static ((+++) <$> g <*> h)+ Static g ||| Static h = Static ((|||) <$> g <*> h)+
+ Data/Bifunctor/Apply.hs view
@@ -0,0 +1,62 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Bifunctor.Apply+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Bifunctor.Apply ( + -- * Functors+ -- * Applyable bifunctors+ Biapply(..)+ , (<<$>>)+ , (<<..>>)+ , bilift2+ , bilift3+ , module Data.Bifunctor+ ) where++-- import _everything_+import Data.Bifunctor++infixl 4 <<$>>, <<.>>, <<., .>>, <<..>>++(<<$>>) :: (a -> b) -> a -> b+(<<$>>) = id++-- | A strong lax semi-monoidal endofunctor. +-- This is equivalent to an 'Applicative' without 'pure'.+-- +-- Laws: +--+-- > associative composition: (.) <$> u <.> v <.> w = u <.> (v <.> w)+class Bifunctor p => Biapply p where+ (<<.>>) :: p (a -> b) (c -> d) -> p a c -> p b d++ -- | a .> b = const id <$> a <.> b+ (.>>) :: p a b -> p c d -> p c d+ a .>> b = bimap (const id) (const id) <<$>> a <<.>> b++ -- | a <. b = const <$> a <.> b+ (<<.) :: p a b -> p c d -> p a b+ a <<. b = bimap const const <<$>> a <<.>> b++(<<..>>) :: Biapply p => p a c -> p (a -> b) (c -> d) -> p b d+(<<..>>) = bilift2 (flip id) (flip id) ++-- | Lift a binary function into a comonad with zipping+bilift2 :: Biapply w => (a -> b -> c) -> (d -> e -> f) -> w a d -> w b e -> w c f+bilift2 f g a b = bimap f g <<$>> a <<.>> b+{-# INLINE bilift2 #-}++-- | Lift a ternary function into a comonad with zipping+bilift3 :: Biapply w => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h+bilift3 f g a b c = bimap f g <<$>> a <<.>> b <<.>> c+{-# INLINE bilift3 #-}++instance Biapply (,) where+ (f, g) <<.>> (a, b) = (f a, g b)
+ Data/Functor/Alt.hs view
@@ -0,0 +1,166 @@+{-# LANGUAGE FlexibleContexts #-}+-----------------------------------------------------------------------------+-- |+-- Module : Data.Functor.Alt+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Functor.Alt+ ( Alt(..)+ , module Data.Functor.Apply+ ) where++import Control.Applicative hiding (some, many)+import Control.Arrow+-- import Control.Exception+import Control.Monad+import Control.Monad.Trans.Identity+-- import Control.Monad.Trans.Cont+import Control.Monad.Trans.Error+import Control.Monad.Trans.List+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+import qualified Control.Monad.Trans.RWS.Strict as Strict+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Strict as Strict+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.State.Lazy as Lazy+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.Sequence (Seq)+import qualified Data.Map as Map+import Data.Map (Map)+import Data.Monoid+import Prelude hiding (id, (.))++infixl 3 <!> ++-- | Laws:+-- +-- > <!> is associative: (a <!> b) <!> c = a <!> (b <!> c)+-- > <$> left-distributes over <!>: f <$> (a <!> b) = (f <$> a) <!> (f <$> b)+--+-- If extended to an 'Alternative' then '<!>' should equal '<|>'.+--+-- Ideally, an instance of 'Alt' also satisfies the \"left distributon\" law of +-- MonadPlus with respect to <.>:+--+-- > <.> right-distributes over <!>: (a <!> b) <.> c = (a <.> c) <!> (b <.> c)+-- +-- But 'Maybe', 'IO', @'Either' a@, @'ErrorT' e m@, and 'STM' satisfy the alternative +-- \"left catch\" law instead:+-- +-- > pure a <!> b = pure a+--+-- However, this variation cannot be stated purely in terms of the dependencies of 'Alt'.+--+-- When and if MonadPlus is successfully refactored, this class should also +-- be refactored to remove these instances.+--+-- The right distributive law should extend in the cases where the a 'Bind' or 'Monad' is+-- provided to yield variations of the right distributive law:+--+-- > (m <!> n) >>- f = (m >>- f) <!> (m >>- f)+-- > (m <!> n) >>= f = (m >>= f) <!> (m >>= f)++class Functor f => Alt f where+ -- | @(<|>)@ without a required @empty@+ (<!>) :: f a -> f a -> f a++ some :: Applicative f => f a -> f [a]+ some v = some_v+ where many_v = some_v <!> pure []+ some_v = (:) <$> v <*> many_v++ many :: Applicative f => f a -> f [a]+ many v = many_v+ where many_v = some_v <!> pure []+ some_v = (:) <$> v <*> many_v+++instance Alt (Either a) where+ Left _ <!> b = b+ a <!> _ = a++-- | This instance does not actually satisfy the (<.>) right distributive law+-- It instead satisfies the "Left-Catch" law+instance Alt IO where+ m <!> n = m `catch` \_ -> n++instance Alt [] where+ (<!>) = (++)++instance Alt Maybe where+ Nothing <!> b = b+ a <!> _ = a++instance Alt Option where+ (<!>) = (<|>)++instance MonadPlus m => Alt (WrappedMonad m) where+ (<!>) = (<|>)++instance ArrowPlus a => Alt (WrappedArrow a b) where+ (<!>) = (<|>) ++instance Ord k => Alt (Map k) where+ (<!>) = Map.union++instance Alt IntMap where+ (<!>) = IntMap.union++instance Alt Seq where+ (<!>) = mappend++instance Alternative f => Alt (WrappedApplicative f) where+ WrapApplicative a <!> WrapApplicative b = WrapApplicative (a <|> b)++instance Alt f => Alt (IdentityT f) where+ IdentityT a <!> IdentityT b = IdentityT (a <!> b)++instance Alt f => Alt (ReaderT e f) where+ ReaderT a <!> ReaderT b = ReaderT $ \e -> a e <!> b e++instance (Bind f, Monad f) => Alt (MaybeT f) where+ MaybeT a <!> MaybeT b = MaybeT $ do+ v <- a+ case v of+ Nothing -> b+ Just _ -> return v+ +instance (Bind f, Monad f) => Alt (ErrorT e f) where+ ErrorT m <!> ErrorT n = ErrorT $ do+ a <- m+ case a of+ Left _ -> n+ Right r -> return (Right r)++instance Apply f => Alt (ListT f) where+ ListT a <!> ListT b = ListT $ (<!>) <$> a <.> b++instance Alt f => Alt (Strict.StateT e f) where+ Strict.StateT m <!> Strict.StateT n = Strict.StateT $ \s -> m s <!> n s+ +instance Alt f => Alt (Lazy.StateT e f) where+ Lazy.StateT m <!> Lazy.StateT n = Lazy.StateT $ \s -> m s <!> n s++instance Alt f => Alt (Strict.WriterT w f) where+ Strict.WriterT m <!> Strict.WriterT n = Strict.WriterT $ m <!> n+ +instance Alt f => Alt (Lazy.WriterT w f) where+ Lazy.WriterT m <!> Lazy.WriterT n = Lazy.WriterT $ m <!> n+ +instance Alt f => Alt (Strict.RWST r w s f) where+ Strict.RWST m <!> Strict.RWST n = Strict.RWST $ \r s -> m r s <!> n r s++instance Alt f => Alt (Lazy.RWST r w s f) where+ Lazy.RWST m <!> Lazy.RWST n = Lazy.RWST $ \r s -> m r s <!> n r s
+ Data/Functor/Apply.hs view
@@ -0,0 +1,30 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Functor.Apply+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Functor.Apply ( + -- * Functors+ Functor(..)+ , (<$>) -- :: Functor f => (a -> b) -> f a -> f b+ , ( $>) -- :: Functor f => f a -> b -> f b ++ -- * Apply - a strong lax semimonoidal endofunctor++ , Apply(..)+ , (<..>) -- :: Apply w => w a -> w (a -> b) -> w b+ , liftF2 -- :: Apply w => (a -> b -> c) -> w a -> w b -> w c+ , liftF3 -- :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d++ -- * Wrappers+ , WrappedApplicative(..)+ , MaybeApply(..)+ ) where++import Data.Functor.Bind
+ Data/Functor/Bind.hs view
@@ -0,0 +1,460 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+-----------------------------------------------------------------------------+-- |+-- Module : Data.Functor.Bind+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+-- NB: The definitions exported through "Data.Functor.Apply" need to be +-- included here because otherwise the instances for the transformers package+-- have orphaned heads.+----------------------------------------------------------------------------+module Data.Functor.Bind ( + -- * Functors+ Functor(..)+ , (<$>) -- :: Functor f => (a -> b) -> f a -> f b+ , ( $>) -- :: Functor f => f a -> b -> f b + -- * Applyable functors+ , Apply(..)+ , (<..>) -- :: Apply w => w a -> w (a -> b) -> w b+ , liftF2 -- :: Apply w => (a -> b -> c) -> w a -> w b -> w c+ , liftF3 -- :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d+ -- * Wrappers+ , WrappedApplicative(..)+ , MaybeApply(..)+ -- * Bindable functors+ , Bind(..)+ , (-<<)+ , (-<-)+ , (->-)+ , apDefault+ , returning+ ) where++-- import _everything_+import Control.Applicative+import Control.Arrow+import Control.Category+import Control.Comonad+import Control.Monad (ap)+import Control.Monad.Instances+import Control.Monad.Trans.Cont+import Control.Monad.Trans.Error+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+import Control.Monad.Trans.List+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.State.Lazy as Lazy+import qualified Control.Monad.Trans.Writer.Lazy as Lazy+import qualified Control.Monad.Trans.RWS.Strict as Strict+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Strict as Strict+import Data.Functor+import Data.Functor.Extend+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Functor.Product+import qualified Data.IntMap as IntMap+import Data.IntMap (IntMap)+import qualified Data.Map as Map+import Data.Map (Map)+import Data.Semigroup hiding (Product)+import Data.Sequence (Seq)+import Data.Tree (Tree)+import Prelude hiding (id, (.))++infixl 1 >>-+infixr 1 -<<+infixl 4 <.>, <., .>, <..>, $>++-- | TODO: move into Data.Functor+($>) :: Functor f => f a -> b -> f b+($>) = flip (<$)++-- | A strong lax semi-monoidal endofunctor. +-- This is equivalent to an 'Applicative' without 'pure'.+-- +-- Laws: +--+-- > associative composition: (.) <$> u <.> v <.> w = u <.> (v <.> w)+class Functor f => Apply f where+ (<.>) :: f (a -> b) -> f a -> f b++ -- | a .> b = const id <$> a <.> b+ (.>) :: f a -> f b -> f b+ a .> b = const id <$> a <.> b++ -- | a <. b = const <$> a <.> b+ (<.) :: f a -> f b -> f a+ a <. b = const <$> a <.> b++instance (Apply f, Apply g) => Apply (Compose f g) where+ Compose f <.> Compose x = Compose ((<.>) <$> f <.> x) ++instance (Apply f, Apply g) => Apply (Product f g) where+ Pair f g <.> Pair x y = Pair (f <.> x) (g <.> y)++instance Semigroup m => Apply ((,)m) where+ (m, f) <.> (n, a) = (m <> n, f a)+ (m, a) <. (n, _) = (m <> n, a) + (m, _) .> (n, b) = (m <> n, b)++instance Apply (Either a) where+ Left a <.> _ = Left a+ Right _ <.> Left a = Left a+ Right f <.> Right b = Right (f b)++ Left a <. _ = Left a+ Right _ <. Left a = Left a+ Right a <. Right _ = Right a++ Left a .> _ = Left a+ Right _ .> Left a = Left a+ Right _ .> Right b = Right b++instance Semigroup m => Apply (Const m) where+ Const m <.> Const n = Const (m <> n)+ Const m <. Const n = Const (m <> n)+ Const m .> Const n = Const (m <> n)++instance Apply ((->)m) where+ (<.>) = (<*>)+ (<. ) = (<* )+ ( .>) = ( *>)++instance Apply ZipList where+ (<.>) = (<*>)+ (<. ) = (<* )+ ( .>) = ( *>)++instance Apply [] where+ (<.>) = (<*>)+ (<. ) = (<* )+ ( .>) = ( *>)++instance Apply IO where+ (<.>) = (<*>)+ (<. ) = (<* )+ ( .>) = ( *>)++instance Apply Maybe where+ (<.>) = (<*>)+ (<. ) = (<* )+ ( .>) = ( *>)++instance Apply Option where+ (<.>) = (<*>)+ (<. ) = (<* ) + ( .>) = ( *>)++instance Apply Identity where+ (<.>) = (<*>)+ (<. ) = (<* )+ ( .>) = ( *>)++instance Apply w => Apply (IdentityT w) where+ IdentityT wa <.> IdentityT wb = IdentityT (wa <.> wb)++instance Monad m => Apply (WrappedMonad m) where+ (<.>) = (<*>) + (<. ) = (<* )+ ( .>) = ( *>)++instance Arrow a => Apply (WrappedArrow a b) where+ (<.>) = (<*>) + (<. ) = (<* )+ ( .>) = ( *>)++-- | A Map is not 'Applicative', but it is an instance of 'Apply'+instance Ord k => Apply (Map k) where+ (<.>) = Map.intersectionWith id+ (<. ) = Map.intersectionWith const+ ( .>) = Map.intersectionWith (const id)++-- | An IntMap is not 'Applicative', but it is an instance of 'Apply'+instance Apply IntMap where+ (<.>) = IntMap.intersectionWith id+ (<. ) = IntMap.intersectionWith const+ ( .>) = IntMap.intersectionWith (const id)++instance Apply Seq where+ (<.>) = ap++instance Apply Tree where+ (<.>) = (<*>) + (<. ) = (<* ) + ( .>) = ( *>) ++-- MaybeT is _not_ the same as Compose f Maybe+instance (Bind m, Monad m) => Apply (MaybeT m) where+ (<.>) = apDefault++-- ErrorT e is _not_ the same as Compose f (Either e)+instance (Bind m, Monad m) => Apply (ErrorT e m) where+ (<.>) = apDefault++instance Apply m => Apply (ReaderT e m) where+ ReaderT f <.> ReaderT a = ReaderT $ \e -> f e <.> a e ++instance Apply m => Apply (ListT m) where+ ListT f <.> ListT a = ListT $ (<.>) <$> f <.> a++-- unfortunately, WriterT has its wrapped product in the wrong order to just use (<.>) instead of flap+instance (Apply m, Semigroup w) => Apply (Strict.WriterT w m) where+ Strict.WriterT f <.> Strict.WriterT a = Strict.WriterT $ flap <$> f <.> a where+ flap (x,m) (y,n) = (x y, m <> n)++instance (Apply m, Semigroup w) => Apply (Lazy.WriterT w m) where+ Lazy.WriterT f <.> Lazy.WriterT a = Lazy.WriterT $ flap <$> f <.> a where+ flap ~(x,m) ~(y,n) = (x y, m <> n)+ +instance Bind m => Apply (Strict.StateT s m) where+ (<.>) = apDefault++instance Bind m => Apply (Lazy.StateT s m) where+ (<.>) = apDefault++instance (Bind m, Semigroup w) => Apply (Strict.RWST r w s m) where+ (<.>) = apDefault++instance (Bind m, Semigroup w) => Apply (Lazy.RWST r w s m) where+ (<.>) = apDefault++instance Apply (ContT r m) where+ ContT f <.> ContT v = ContT $ \k -> f $ \g -> v (k . g)++-- | Wrap an 'Applicative' to be used as a member of 'Apply'+newtype WrappedApplicative f a = WrapApplicative { unwrapApplicative :: f a } ++instance Functor f => Functor (WrappedApplicative f) where+ fmap f (WrapApplicative a) = WrapApplicative (f <$> a)++instance Applicative f => Apply (WrappedApplicative f) where+ WrapApplicative f <.> WrapApplicative a = WrapApplicative (f <*> a)+ WrapApplicative a <. WrapApplicative b = WrapApplicative (a <* b)+ WrapApplicative a .> WrapApplicative b = WrapApplicative (a *> b)++instance Applicative f => Applicative (WrappedApplicative f) where+ pure = WrapApplicative . pure+ WrapApplicative f <*> WrapApplicative a = WrapApplicative (f <*> a)+ WrapApplicative a <* WrapApplicative b = WrapApplicative (a <* b)+ WrapApplicative a *> WrapApplicative b = WrapApplicative (a *> b)++instance Alternative f => Alternative (WrappedApplicative f) where+ empty = WrapApplicative empty+ WrapApplicative a <|> WrapApplicative b = WrapApplicative (a <|> b)++-- | Transform a Apply into an Applicative by adding a unit.+newtype MaybeApply f a = MaybeApply { runMaybeApply :: Either (f a) a }++instance Functor f => Functor (MaybeApply f) where+ fmap f (MaybeApply (Right a)) = MaybeApply (Right (f a ))+ fmap f (MaybeApply (Left fa)) = MaybeApply (Left (f <$> fa))++instance Apply f => Apply (MaybeApply f) where+ MaybeApply (Right f) <.> MaybeApply (Right a) = MaybeApply (Right (f a ))+ MaybeApply (Right f) <.> MaybeApply (Left fa) = MaybeApply (Left (f <$> fa))+ MaybeApply (Left ff) <.> MaybeApply (Right a) = MaybeApply (Left (($a) <$> ff))+ MaybeApply (Left ff) <.> MaybeApply (Left fa) = MaybeApply (Left (ff <.> fa))++ MaybeApply a <. MaybeApply (Right _) = MaybeApply a+ MaybeApply (Right a) <. MaybeApply (Left fb) = MaybeApply (Left (a <$ fb))+ MaybeApply (Left fa) <. MaybeApply (Left fb) = MaybeApply (Left (fa <. fb))++ MaybeApply (Right _) .> MaybeApply b = MaybeApply b+ MaybeApply (Left fa) .> MaybeApply (Right b) = MaybeApply (Left (fa $> b ))+ MaybeApply (Left fa) .> MaybeApply (Left fb) = MaybeApply (Left (fa .> fb))+ +instance Apply f => Applicative (MaybeApply f) where+ pure a = MaybeApply (Right a)+ (<*>) = (<.>)+ (<* ) = (<. )+ ( *>) = ( .>)++-- | A variant of '<.>' with the arguments reversed.+(<..>) :: Apply w => w a -> w (a -> b) -> w b+(<..>) = liftF2 (flip id)+{-# INLINE (<..>) #-}++-- | Lift a binary function into a comonad with zipping+liftF2 :: Apply w => (a -> b -> c) -> w a -> w b -> w c+liftF2 f a b = f <$> a <.> b+{-# INLINE liftF2 #-}++-- | Lift a ternary function into a comonad with zipping+liftF3 :: Apply w => (a -> b -> c -> d) -> w a -> w b -> w c -> w d+liftF3 f a b c = f <$> a <.> b <.> c+{-# INLINE liftF3 #-}++instance Extend f => Extend (MaybeApply f) where+ duplicate w@(MaybeApply Right{}) = MaybeApply (Right w)+ duplicate (MaybeApply (Left fa)) = MaybeApply (Left (extend (MaybeApply . Left) fa))++instance Comonad f => Comonad (MaybeApply f) where+ extract (MaybeApply (Left fa)) = extract fa+ extract (MaybeApply (Right a)) = a++instance Apply (Cokleisli w a) where+ Cokleisli f <.> Cokleisli a = Cokleisli (\w -> (f w) (a w))++-- | A 'Monad' sans 'return'. +-- +-- Minimal definition: Either 'join' or '>>-'+--+-- If defining both, then the following laws (the default definitions) must hold:+--+-- > join = (>>- id)+-- > m >>- f = join (fmap f m)+--+-- Laws:+--+-- > induced definition of <.>: f <.> x = f >>- (<$> x)+-- +-- Finally, there are two associativity conditions:+-- +-- > associativity of (>>-): (m >>- f) >>- g == m >>- (\x -> f x >>- g)+-- > associativity of join: join . join = join . fmap join+--+-- These can both be seen as special cases of the constraint that+--+-- > associativity of (->-): (f ->- g) ->- h = f ->- (g ->- h)+--++class Apply m => Bind m where+ (>>-) :: m a -> (a -> m b) -> m b+ m >>- f = join (fmap f m)++ join :: m (m a) -> m a+ join = (>>- id)++returning :: Functor f => f a -> (a -> b) -> f b+returning = flip fmap++(-<<) :: Bind m => (a -> m b) -> m a -> m b+(-<<) = flip (>>-)++(->-) :: Bind m => (a -> m b) -> (b -> m c) -> a -> m c+f ->- g = \a -> f a >>- g++(-<-) :: Bind m => (b -> m c) -> (a -> m b) -> a -> m c+g -<- f = \a -> f a >>- g++apDefault :: Bind f => f (a -> b) -> f a -> f b+apDefault f x = f >>- \f' -> f' <$> x++instance Semigroup m => Bind ((,)m) where+ ~(m, a) >>- f = let (n, b) = f a in (m <> n, b)++instance Bind (Either a) where+ Left a >>- _ = Left a+ Right a >>- f = f a ++instance (Bind f, Bind g) => Bind (Product f g) where+ Pair m n >>- f = Pair (m >>- fstP . f) (n >>- sndP . f) where+ fstP (Pair a _) = a+ sndP (Pair _ b) = b++instance Bind ((->)m) where+ f >>- g = \e -> g (f e) e ++instance Bind [] where+ (>>-) = (>>=)++instance Bind IO where+ (>>-) = (>>=)++instance Bind Maybe where+ (>>-) = (>>=)++instance Bind Option where+ (>>-) = (>>=)++instance Bind Identity where+ (>>-) = (>>=)++instance Bind m => Bind (IdentityT m) where+ IdentityT m >>- f = IdentityT (m >>- runIdentityT . f)++instance Monad m => Bind (WrappedMonad m) where+ WrapMonad m >>- f = WrapMonad $ m >>= unwrapMonad . f ++instance (Bind m, Monad m) => Bind (MaybeT m) where+ (>>-) = (>>=) -- distributive law requires Monad to inject @Nothing@++instance (Bind m, Monad m) => Bind (ListT m) where+ (>>-) = (>>=) -- distributive law requires Monad to inject @[]@++instance (Bind m, Monad m) => Bind (ErrorT e m) where+ m >>- k = ErrorT $ do+ a <- runErrorT m + case a of+ Left l -> return (Left l)+ Right r -> runErrorT (k r)++instance Bind m => Bind (ReaderT e m) where+ ReaderT m >>- f = ReaderT $ \e -> m e >>- \x -> runReaderT (f x) e++instance (Bind m, Semigroup w) => Bind (Lazy.WriterT w m) where+ m >>- k = Lazy.WriterT $+ Lazy.runWriterT m >>- \ ~(a, w) -> + Lazy.runWriterT (k a) `returning` \ ~(b, w') -> + (b, w <> w')++instance (Bind m, Semigroup w) => Bind (Strict.WriterT w m) where+ m >>- k = Strict.WriterT $+ Strict.runWriterT m >>- \ (a, w) -> + Strict.runWriterT (k a) `returning` \ (b, w') -> + (b, w <> w')++instance Bind m => Bind (Lazy.StateT s m) where+ m >>- k = Lazy.StateT $ \s -> + Lazy.runStateT m s >>- \ ~(a, s') ->+ Lazy.runStateT (k a) s'++instance Bind m => Bind (Strict.StateT s m) where+ m >>- k = Strict.StateT $ \s -> + Strict.runStateT m s >>- \ ~(a, s') ->+ Strict.runStateT (k a) s'+ +instance (Bind m, Semigroup w) => Bind (Lazy.RWST r w s m) where+ m >>- k = Lazy.RWST $ \r s -> + Lazy.runRWST m r s >>- \ ~(a, s', w) ->+ Lazy.runRWST (k a) r s' `returning` \ ~(b, s'', w') -> + (b, s'', w <> w')++instance (Bind m, Semigroup w) => Bind (Strict.RWST r w s m) where+ m >>- k = Strict.RWST $ \r s -> + Strict.runRWST m r s >>- \ (a, s', w) ->+ Strict.runRWST (k a) r s' `returning` \ (b, s'', w') -> + (b, s'', w <> w')++instance Bind (ContT r m) where+ m >>- k = ContT $ \c -> runContT m $ \a -> runContT (k a) c++{-+instance ArrowApply a => Bind (WrappedArrow a b) where+ (>>-) = (>>=)+-}++-- | 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++-- | An 'IntMap' is a 'Applicative', but it is an instance of 'Bind'+instance Bind IntMap where+ m >>- f = IntMap.mapMaybeWithKey (\k -> IntMap.lookup k . f) m++instance Bind Seq where+ (>>-) = (>>=)++instance Bind Tree where+ (>>-) = (>>=)++instance (Comonad w, Apply w) => ArrowLoop (Cokleisli w) where+ loop (Cokleisli f) = Cokleisli (fst . wfix . extend f') where+ f' wa wb = f ((,) <$> wa <.> (snd <$> wb))
+ Data/Functor/Bind/Trans.hs view
@@ -0,0 +1,66 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Functor.Bind.Trans+-- Copyright : (C) 2011 Edward Kmett,+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Functor.Bind.Trans ( + BindTrans(..)+ ) where++-- import _everything_+import Control.Category+import Control.Monad.Instances+import Control.Monad.Trans.Class+import Control.Monad.Trans.Cont+-- import Control.Monad.Trans.Error+import Control.Monad.Trans.Identity+-- import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+-- import Control.Monad.Trans.List+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.State.Lazy as Lazy+import qualified Control.Monad.Trans.Writer.Lazy as Lazy+import qualified Control.Monad.Trans.RWS.Strict as Strict+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Strict as Strict+import Data.Functor.Bind+import Data.Monoid+import Data.Semigroup hiding (Product)+import Prelude hiding (id, (.))++-- | A subset of monad transformers can transform any 'Bind' as well.+class MonadTrans t => BindTrans t where+ liftB :: Bind b => b a -> t b a++instance BindTrans IdentityT where+ liftB = IdentityT++instance BindTrans (ReaderT e) where+ liftB = ReaderT . const ++instance (Semigroup w, Monoid w) => BindTrans (Lazy.WriterT w) where+ liftB = Lazy.WriterT . fmap (\a -> (a, mempty))++instance (Semigroup w, Monoid w) => BindTrans (Strict.WriterT w) where+ liftB = Strict.WriterT . fmap (\a -> (a, mempty))++instance BindTrans (Lazy.StateT s) where+ liftB m = Lazy.StateT $ \s -> fmap (\a -> (a, s)) m ++instance BindTrans (Strict.StateT s) where+ liftB m = Strict.StateT $ \s -> fmap (\a -> (a, s)) m ++instance (Semigroup w, Monoid w) => BindTrans (Lazy.RWST r w s) where+ liftB m = Lazy.RWST $ \ _r s -> fmap (\a -> (a, s, mempty)) m+ +instance (Semigroup w, Monoid w) => BindTrans (Strict.RWST r w s) where+ liftB m = Strict.RWST $ \ _r s -> fmap (\a -> (a, s, mempty)) m++instance BindTrans (ContT r) where+ liftB m = ContT (m >>-)
+ Data/Functor/Plus.hs view
@@ -0,0 +1,116 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Functor.Plus+-- Copyright : (C) 2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Functor.Plus+ ( Plus(..)+ , module Data.Functor.Alt+ ) where++import Control.Applicative hiding (some, many)+import Control.Arrow+-- import Control.Exception+import Control.Monad+import Control.Monad.Trans.Identity+-- import Control.Monad.Trans.Cont+import Control.Monad.Trans.Error+import Control.Monad.Trans.List+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader+import qualified Control.Monad.Trans.RWS.Strict as Strict+import qualified Control.Monad.Trans.State.Strict as Strict+import qualified Control.Monad.Trans.Writer.Strict as Strict+import qualified Control.Monad.Trans.RWS.Lazy as Lazy+import qualified Control.Monad.Trans.State.Lazy as Lazy+import qualified Control.Monad.Trans.Writer.Lazy as Lazy+import Data.Functor.Apply+import Data.Functor.Alt+import Data.Functor.Bind+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 Data.Monoid+import Prelude hiding (id, (.))++-- | Laws:+-- +-- > zero <!> m = m+-- > m <!> zero = m+--+-- If extended to an 'Alternative' then 'zero' should equal 'empty'.++class Alt f => Plus f where+ zero :: f a ++instance Plus IO where+ zero = error "zero"++instance Plus [] where+ zero = []++instance Plus Maybe where+ zero = Nothing++instance Plus Option where+ zero = empty++instance MonadPlus m => Plus (WrappedMonad m) where+ zero = empty++instance ArrowPlus a => Plus (WrappedArrow a b) where+ zero = empty++instance Ord k => Plus (Map k) where+ zero = Map.empty++instance Plus IntMap where+ zero = IntMap.empty++instance Plus Seq where+ zero = mempty++instance Alternative f => Plus (WrappedApplicative f) where+ zero = empty++instance Plus f => Plus (IdentityT f) where+ zero = IdentityT zero++instance Plus f => Plus (ReaderT e f) where+ zero = ReaderT $ \_ -> zero++instance (Bind f, Monad f) => Plus (MaybeT f) where+ zero = MaybeT $ return zero+ +instance (Bind f, Monad f, Error e) => Plus (ErrorT e f) where+ zero = ErrorT $ return $ Left noMsg++instance (Apply f, Applicative f) => Plus (ListT f) where+ zero = ListT $ pure []++instance (Plus f) => Plus (Strict.StateT e f) where+ zero = Strict.StateT $ \_ -> zero+ +instance (Plus f) => Plus (Lazy.StateT e f) where+ zero = Lazy.StateT $ \_ -> zero++instance Plus f => Plus (Strict.WriterT w f) where+ zero = Strict.WriterT zero+ +instance Plus f => Plus (Lazy.WriterT w f) where+ zero = Lazy.WriterT zero+ +instance Plus f => Plus (Strict.RWST r w s f) where+ zero = Strict.RWST $ \_ _ -> zero ++instance Plus f => Plus (Lazy.RWST r w s f) where+ zero = Lazy.RWST $ \_ _ -> zero
+ Data/Semigroup/Bifoldable.hs view
@@ -0,0 +1,68 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Semigroup.Foldable+-- Copyright : (C) 2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Semigroup.Bifoldable+ ( Bifoldable1(..)+ , bitraverse1_+ , bifor1_+ , bisequenceA1_+ , bifoldMapDefault1+ ) where++import Prelude hiding (foldr)+import Data.Bifoldable+import Data.Functor.Apply+import Data.Semigroup+import Data.Monoid++class Bifoldable t => Bifoldable1 t where+ bifold1 :: Semigroup m => t m m -> m+ bifold1 = bifoldMap1 id id++ bifoldMap1 :: Semigroup m => (a -> m) -> (b -> m) -> t a b -> m+ bifoldMap1 f g = maybe (error "bifoldMap1") id . getOption . bifoldMap (Option . Just . f) (Option . Just . g)++instance Bifoldable1 Either where+ bifoldMap1 f _ (Left a) = f a+ bifoldMap1 _ g (Right b) = g b++instance Bifoldable1 (,) where+ bifoldMap1 f g (a, b) = f a <> g b++newtype Act f a = Act { getAct :: f a }++instance Apply f => Semigroup (Act f a) where+ Act a <> Act b = Act (a .> b)++instance Functor f => Functor (Act f) where+ fmap f (Act a) = Act (f <$> a)+ b <$ Act a = Act (b <$ a)++bitraverse1_ :: (Bifoldable1 t, Apply f) => (a -> f b) -> (c -> f d) -> t a c -> f ()+bitraverse1_ f g t = getAct (bifoldMap1 (Act . ignore . f) (Act . ignore . g) t)+{-# INLINE bitraverse1_ #-}++bifor1_ :: (Bifoldable1 t, Apply f) => t a c -> (a -> f b) -> (c -> f d) -> f ()+bifor1_ t f g = bitraverse1_ f g t +{-# INLINE bifor1_ #-}++ignore :: Functor f => f a -> f ()+ignore = (() <$)++bisequenceA1_ :: (Bifoldable1 t, Apply f) => t (f a) (f b) -> f ()+bisequenceA1_ t = getAct (bifoldMap1 (Act . ignore) (Act . ignore) t)+{-# INLINE bisequenceA1_ #-}++-- | Usable default for foldMap, but only if you define bifoldMap1 yourself+bifoldMapDefault1 :: (Bifoldable1 t, Monoid m) => (a -> m) -> (b -> m) -> t a b -> m+bifoldMapDefault1 f g = unwrapMonoid . bifoldMap (WrapMonoid . f) (WrapMonoid . g)+{-# INLINE bifoldMapDefault1 #-}+
+ Data/Semigroup/Bitraversable.hs view
@@ -0,0 +1,39 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Semigroup.Bitraversable+-- Copyright : (C) 2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Semigroup.Bitraversable+ ( Bitraversable1(..)+ , bifoldMap1Default+ ) where++import Control.Applicative+import Data.Functor.Apply+import Data.Semigroup.Bifoldable+import Data.Bitraversable+import Data.Bifunctor+import Data.Semigroup++class (Bifoldable1 t, Bitraversable t) => Bitraversable1 t where+ bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> t a c -> f (t b d)+ bitraverse1 f g = bisequence1 . bimap f g++ bisequence1 :: Apply f => t (f a) (f b) -> f (t a b)+ bisequence1 = bitraverse1 id id++bifoldMap1Default :: (Bitraversable1 t, Semigroup m) => (a -> m) -> (b -> m) -> t a b -> m+bifoldMap1Default f g = getConst . bitraverse1 (Const . f) (Const . g)++instance Bitraversable1 Either where+ bitraverse1 f _ (Left a) = Left <$> f a+ bitraverse1 _ g (Right b) = Right <$> g b++instance Bitraversable1 (,) where+ bitraverse1 f g (a, b) = (,) <$> f a <.> g b
+ Data/Semigroup/Foldable.hs view
@@ -0,0 +1,61 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Semigroup.Foldable+-- Copyright : (C) 2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Semigroup.Foldable+ ( Foldable1(..)+ , traverse1_+ , for1_+ , sequenceA1_+ , foldMapDefault1+ ) where++import Prelude hiding (foldr)+import Data.Foldable+import Data.Functor.Apply+import Data.Semigroup+import Data.Monoid++class Foldable t => Foldable1 t where+ fold1 :: Semigroup m => t m -> m+ foldMap1 :: Semigroup m => (a -> m) -> t a -> m++ foldMap1 f = maybe (error "foldMap1") id . getOption . foldMap (Option . Just . f) + fold1 = foldMap1 id++newtype Act f a = Act { getAct :: f a }++instance Apply f => Semigroup (Act f a) where+ Act a <> Act b = Act (a .> b)++instance Functor f => Functor (Act f) where+ fmap f (Act a) = Act (f <$> a)+ b <$ Act a = Act (b <$ a)++traverse1_ :: (Foldable1 t, Apply f) => (a -> f b) -> t a -> f ()+traverse1_ f t = () <$ getAct (foldMap1 (Act . f) t)+{-# INLINE traverse1_ #-}++for1_ :: (Foldable1 t, Apply f) => t a -> (a -> f b) -> f ()+for1_ = flip traverse1_+{-# INLINE for1_ #-}++sequenceA1_ :: (Foldable1 t, Apply f) => t (f a) -> f ()+sequenceA1_ t = () <$ getAct (foldMap1 Act t)+{-# INLINE sequenceA1_ #-}++-- | Usable default for foldMap, but only if you define foldMap1 yourself+foldMapDefault1 :: (Foldable1 t, Monoid m) => (a -> m) -> t a -> m+foldMapDefault1 f = unwrapMonoid . foldMap (WrapMonoid . f)+{-# INLINE foldMapDefault1 #-}++-- toStream :: Foldable1 t => t a -> Stream a+-- concat1 :: Foldable1 t => t (Stream a) -> Stream a+-- concatMap1 :: Foldable1 t => (a -> Stream b) -> t a -> Stream b
+ Data/Semigroup/Traversable.hs view
@@ -0,0 +1,31 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Semigroup.Traversable+-- Copyright : (C) 2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Semigroup.Traversable+ ( Traversable1(..)+ , foldMap1Default+ ) where++import Control.Applicative+import Data.Functor.Apply+import Data.Semigroup.Foldable+import Data.Traversable+import Data.Semigroup++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)++ sequence1 = traverse1 id+ traverse1 f = sequence1 . fmap f++foldMap1Default :: (Traversable1 f, Semigroup m) => (a -> m) -> f a -> m+foldMap1Default f = getConst . traverse1 (Const . f)
+ Data/Semigroupoid.hs view
@@ -0,0 +1,35 @@+-----------------------------------------------------------------------------+-- |+-- Module : Data.Semigroupoid+-- Copyright : (C) 2007-2011 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+-- A semigroupoid satisfies all of the requirements to be a Category except +-- for the existence of identity arrows.+----------------------------------------------------------------------------+module Data.Semigroupoid (Semigroupoid(..)) where++import Control.Arrow+import Data.Functor.Bind+import Control.Comonad+import Data.Functor.Contravariant++-- | 'Control.Category.Category' sans 'Control.Category.id'+class Semigroupoid c where+ o :: c j k -> c i j -> c i k++instance Semigroupoid (->) where+ o = (.) ++instance Bind m => Semigroupoid (Kleisli m) where+ Kleisli g `o` Kleisli f = Kleisli $ \a -> f a >>- g++instance Extend w => Semigroupoid (Cokleisli w) where+ Cokleisli f `o` Cokleisli g = Cokleisli $ f . extend g++instance Semigroupoid Op where+ Op f `o` Op g = Op (g `o` f)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 2011 Edward Kmett++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/runhaskell+> module Main (main) where++> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ semigroupoids.cabal view
@@ -0,0 +1,81 @@+name: semigroupoids+category: Control, Comonads+version: 1.0.0+license: BSD3+cabal-version: >= 1.6+license-file: LICENSE+author: Edward A. Kmett+maintainer: Edward A. Kmett <ekmett@gmail.com>+stability: provisional+homepage: http://github.com/ekmett/semigroupoids+copyright: Copyright (C) 2011 Edward A. Kmett+build-type: Simple+synopsis: Haskell 98: Semigroupoids: Categories sans id, Applicative sans pure, Monad sans return, Alternative sans empty+description: + Provides a wide array of semigroupoids and operations for working with semigroupds.+ .+ A Semigroupoid is a Category without the requirement of identity arrows for every object in the category.+ .+ When working with comonads you often have the @\<*\>@ portion of an @Applicative@, but+ not the @pure@. This was captured in Uustalu and Vene's \"Essence of Dataflow Programming\"+ in the form of the @ComonadZip@ class in the days before @Applicative@. Apply provides a weaker invariant, but for the comonads used for data flow programming (found in the streams package), this invariant is preserved. Applicative function composition forms a semigroupoid. + .+ Similarly many structures are nearly a comonad, but not quite, for instance lists provide a reasonable 'extend' operation in the form of 'tails', but do not always contain a value.+ .+ .+ Ideally the following relationships would hold:+ .+ > Traversable <---- Foldable <--- Functor ------> Alt ---------> Plus + > | | | | + > v v v v + > Traversable1 <--- Foldable1 Apply --------> Applicative -> Alternative+ > | | | + > v v v + > Bind ---------> Monad -------> MonadPlus + > + > + >+ > Bitraversable <-- Bifoldable <- Bifunctor Semigroupoid+ > | | | |+ > v v v v+ > Bitraversable1 <- Bifoldable1 Biapply Category+ > |+ > v+ > Arrow+ . + This lets us remove many of the restrictions from various monad transformers+ as in many cases the binding operation or @\<*\>@ operation does not require them.+ .+ Finally, to work with these weaker structures it is beneficial to have containers+ that can provide stronger guarantees about their contents, so versions of 'Traversable'+ and 'Foldable' that can be folded with just a 'Semigroup' are added.++source-repository head+ type: git+ location: git://github.com/ekmett/semigroupoids.git++library+ build-depends: + base >= 4 && < 4.4,+ transformers >= 0.2.0 && < 0.3,+ containers >= 0.4.0 && < 0.5,+ contravariant >= 0.1.2 && < 0.2,+ comonad >= 1.0 && < 1.1, + semigroups >= 0.3.2 && < 0.4,+ bifunctors >= 0.1 && < 0.2++ exposed-modules:+ Control.Arrow.Static+ Data.Bifunctor.Apply,+ Data.Functor.Alt,+ Data.Functor.Apply,+ Data.Functor.Bind,+ Data.Functor.Bind.Trans,+ Data.Functor.Plus,+ Data.Semigroup.Bifoldable,+ Data.Semigroup.Bitraversable+ Data.Semigroup.Foldable,+ Data.Semigroup.Traversable+ Data.Semigroupoid++ ghc-options: -Wall