bifunctors 0.1 → 0.1.1
raw patch · 5 files changed
+177/−2 lines, 5 filesdep +semigroupoidsdep +semigroupsPVP ok
version bump matches the API change (PVP)
Dependencies added: semigroupoids, semigroups
API changes (from Hackage documentation)
+ Data.Bifoldable: biforM_ :: (Bifoldable t, Monad m) => t a b -> (a -> m c) -> (b -> m d) -> m ()
+ Data.Bifunctor.Apply: (.>>) :: Biapply p => p a b -> p c d -> p c d
+ Data.Bifunctor.Apply: (<<$>>) :: (a -> b) -> a -> b
+ Data.Bifunctor.Apply: (<<.) :: Biapply p => p a b -> p c d -> p a b
+ Data.Bifunctor.Apply: (<<..>>) :: Biapply p => p a c -> p (a -> b) (c -> d) -> p b d
+ Data.Bifunctor.Apply: (<<.>>) :: Biapply p => p (a -> b) (c -> d) -> p a c -> p b d
+ Data.Bifunctor.Apply: bilift2 :: Biapply w => (a -> b -> c) -> (d -> e -> f) -> w a d -> w b e -> w c f
+ Data.Bifunctor.Apply: bilift3 :: Biapply w => (a -> b -> c -> d) -> (e -> f -> g -> h) -> w a e -> w b f -> w c g -> w d h
+ Data.Bifunctor.Apply: class Bifunctor p => Biapply p
+ Data.Bifunctor.Apply: instance Biapply (,)
+ Data.Semigroup.Bifoldable: bifold1 :: (Bifoldable1 t, Semigroup m) => t m m -> m
+ Data.Semigroup.Bifoldable: bifoldMap1 :: (Bifoldable1 t, Semigroup m) => (a -> m) -> (b -> m) -> t a b -> m
+ Data.Semigroup.Bifoldable: bifoldMapDefault1 :: (Bifoldable1 t, Monoid m) => (a -> m) -> (b -> m) -> t a b -> m
+ Data.Semigroup.Bifoldable: bifor1_ :: (Bifoldable1 t, Apply f) => t a c -> (a -> f b) -> (c -> f d) -> f ()
+ Data.Semigroup.Bifoldable: bisequenceA1_ :: (Bifoldable1 t, Apply f) => t (f a) (f b) -> f ()
+ Data.Semigroup.Bifoldable: bitraverse1_ :: (Bifoldable1 t, Apply f) => (a -> f b) -> (c -> f d) -> t a c -> f ()
+ Data.Semigroup.Bifoldable: class Bifoldable t => Bifoldable1 t
+ Data.Semigroup.Bifoldable: instance Apply f => Semigroup (Act f a)
+ Data.Semigroup.Bifoldable: instance Bifoldable1 (,)
+ Data.Semigroup.Bifoldable: instance Bifoldable1 Either
+ Data.Semigroup.Bifoldable: instance Functor f => Functor (Act f)
+ Data.Semigroup.Bitraversable: bifoldMap1Default :: (Bitraversable1 t, Semigroup m) => (a -> m) -> (b -> m) -> t a b -> m
+ Data.Semigroup.Bitraversable: bisequence1 :: (Bitraversable1 t, Apply f) => t (f a) (f b) -> f (t a b)
+ Data.Semigroup.Bitraversable: bitraverse1 :: (Bitraversable1 t, Apply f) => (a -> f b) -> (c -> f d) -> t a c -> f (t b d)
+ Data.Semigroup.Bitraversable: class (Bifoldable1 t, Bitraversable t) => Bitraversable1 t
+ Data.Semigroup.Bitraversable: instance Bitraversable1 (,)
+ Data.Semigroup.Bitraversable: instance Bitraversable1 Either
Files
- Data/Bifoldable.hs +1/−0
- Data/Bifunctor/Apply.hs +62/−0
- Data/Semigroup/Bifoldable.hs +68/−0
- Data/Semigroup/Bitraversable.hs +39/−0
- bifunctors.cabal +7/−2
Data/Bifoldable.hs view
@@ -18,6 +18,7 @@ , bitraverse_ , bifor_ , bimapM_+ , biforM_ , bisequenceA_ , bisequence_ , biList
+ 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/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
bifunctors.cabal view
@@ -1,6 +1,6 @@ name: bifunctors category: Data, Functors-version: 0.1+version: 0.1.1 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -19,11 +19,16 @@ library build-depends: - base >= 4 && < 4.4+ base >= 4 && < 4.4,+ semigroups >= 0.5 && < 0.6,+ semigroupoids >= 1.2.2 && < 1.3 exposed-modules: Data.Bifunctor+ Data.Bifunctor.Apply Data.Bifoldable Data.Bitraversable+ Data.Semigroup.Bifoldable+ Data.Semigroup.Bitraversable ghc-options: -Wall