summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphadej <>2019-11-07 19:34:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-11-07 19:34:00 (GMT)
commit0a22625723892bff02b84db011a45094fb4ec5c6 (patch)
treefa98e45f1c27966642f962cf1388d06ec41a419f
parent9c8eb749e5183a4e01f67214863b8b4fa2b0fb4c (diff)
version 1.0.1HEAD1.0.1master
-rwxr-xr-xCHANGELOG.md3
-rw-r--r--assoc.cabal41
-rw-r--r--src/Data/Bifunctor/Assoc.hs35
-rw-r--r--src/Data/Bifunctor/Swap.hs10
4 files changed, 67 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100755
index 0000000..2300822
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,3 @@
+## 1.0.1
+
+- Add `Assoc Const` and `Tagged` instances
diff --git a/assoc.cabal b/assoc.cabal
index b2542a0..ec103d3 100644
--- a/assoc.cabal
+++ b/assoc.cabal
@@ -1,10 +1,10 @@
-cabal-version: 1.12
-name: assoc
-version: 1
-license: BSD3
-license-file: LICENSE
-synopsis: swap and assoc: Symmetric and Semigroupy Bifunctors
-category: Data
+cabal-version: 1.12
+name: assoc
+version: 1.0.1
+license: BSD3
+license-file: LICENSE
+synopsis: swap and assoc: Symmetric and Semigroupy Bifunctors
+category: Data
description:
Provides generalisations of
@swap :: (a,b) -> (b,a)@ and
@@ -12,11 +12,23 @@ description:
to
@Bifunctor@s supporting similar operations (e.g. @Either@, @These@).
-author: Oleg Grenrus <oleg.grenrus@iki.fi>
-maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
-
-build-type: Simple
-tested-with: ghc ==7.0.4 || ==7.2.2 || ==7.4.2 || ==7.6.3 || ==7.8.4 || ==7.10.3 || == 8.0.2 || == 8.2.2 || ==8.4.4 || ==8.6.3
+author: Oleg Grenrus <oleg.grenrus@iki.fi>
+maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
+build-type: Simple
+extra-source-files: CHANGELOG.md
+tested-with:
+ GHC ==7.0.4
+ || ==7.2.2
+ || ==7.4.2
+ || ==7.6.3
+ || ==7.8.4
+ || ==7.10.3
+ || ==8.0.2
+ || ==8.2.2
+ || ==8.4.4
+ || ==8.6.5
+ || ==8.8.1
+ , GHCJS ==8.4
source-repository head
type: git
@@ -26,8 +38,9 @@ library
default-language: Haskell2010
hs-source-dirs: src
build-depends:
- base >=4.3 && <4.13
- , bifunctors >=5.5.2 && <5.6
+ base >=4.3 && <4.14
+ , bifunctors >=5.5.5 && <5.6
+ , tagged >=0.8.6 && <0.9
exposed-modules:
Data.Bifunctor.Assoc
diff --git a/src/Data/Bifunctor/Assoc.hs b/src/Data/Bifunctor/Assoc.hs
index cc6f551..2e38254 100644
--- a/src/Data/Bifunctor/Assoc.hs
+++ b/src/Data/Bifunctor/Assoc.hs
@@ -2,10 +2,12 @@ module Data.Bifunctor.Assoc (
Assoc (..),
) where
-import Data.Bifunctor (Bifunctor (..))
-import Data.Bifunctor.Flip (Flip (..))
-import Data.Bifunctor.Tannen (Tannen (..))
+import Control.Applicative (Const (..))
+import Data.Bifunctor (Bifunctor (..))
+import Data.Bifunctor.Flip (Flip (..))
import Data.Bifunctor.Product (Product (..))
+import Data.Bifunctor.Tannen (Tannen (..))
+import Data.Tagged (Tagged (..))
-- | "Semigroup-y" 'Bifunctor's.
--
@@ -35,6 +37,14 @@ instance Assoc Either where
unassoc (Right (Left b)) = Left (Right b)
unassoc (Right (Right c)) = Right c
+instance Assoc Const where
+ assoc (Const (Const a)) = Const a
+ unassoc (Const a) = Const (Const a)
+
+instance Assoc Tagged where
+ assoc (Tagged a) = Tagged (Tagged a)
+ unassoc (Tagged (Tagged a)) = Tagged a
+
instance Assoc p => Assoc (Flip p) where
assoc = Flip . first Flip . unassoc . second runFlip . runFlip
unassoc = Flip . second Flip . assoc . first runFlip . runFlip
@@ -45,6 +55,7 @@ instance Assoc p => Assoc (Flip p) where
--
-- >>> import Data.Proxy
-- >>> import Test.QuickCheck
+-- >>> import Test.QuickCheck.Instances
-- >>> import Data.Functor.Classes
--
-- >>> :{
@@ -58,6 +69,12 @@ instance Assoc p => Assoc (Flip p) where
-- >>> quickCheck $ assocUnassocLaw (Proxy :: Proxy Either)
-- +++ OK, passed 100 tests.
--
+-- >>> quickCheck $ assocUnassocLaw (Proxy :: Proxy Tagged)
+-- +++ OK, passed 100 tests.
+--
+-- >>> quickCheck $ assocUnassocLaw (Proxy :: Proxy Const)
+-- +++ OK, passed 100 tests.
+--
-- >>> :{
-- let unassocAssocLaw :: (Assoc p, Eq2 p) => Proxy p -> p (p Int Char) Bool -> Bool
-- unassocAssocLaw _ x = liftEq2 eq2 (==) (unassoc (assoc x)) x
@@ -69,6 +86,12 @@ instance Assoc p => Assoc (Flip p) where
-- >>> quickCheck $ unassocAssocLaw (Proxy :: Proxy Either)
-- +++ OK, passed 100 tests.
--
+-- >>> quickCheck $ unassocAssocLaw (Proxy :: Proxy Tagged)
+-- +++ OK, passed 100 tests.
+--
+-- >>> quickCheck $ unassocAssocLaw (Proxy :: Proxy Const)
+-- +++ OK, passed 100 tests.
+--
-- >>> :{
-- let bimapLaw :: (Assoc p, Eq2 p) => Proxy p
-- -> Fun Int Char -> Fun Char Bool -> Fun Bool Int
@@ -84,3 +107,9 @@ instance Assoc p => Assoc (Flip p) where
--
-- >>> quickCheck $ bimapLaw (Proxy :: Proxy Either)
-- +++ OK, passed 100 tests.
+--
+-- >>> quickCheck $ bimapLaw (Proxy :: Proxy Tagged)
+-- +++ OK, passed 100 tests.
+--
+-- >>> quickCheck $ bimapLaw (Proxy :: Proxy Const)
+-- +++ OK, passed 100 tests.
diff --git a/src/Data/Bifunctor/Swap.hs b/src/Data/Bifunctor/Swap.hs
index 0ae33ad..ef631ff 100644
--- a/src/Data/Bifunctor/Swap.hs
+++ b/src/Data/Bifunctor/Swap.hs
@@ -3,12 +3,12 @@ module Data.Bifunctor.Swap (
Swap (..),
) where
-import Data.Bifunctor (Bifunctor (..))
-import Data.Bifunctor.Flip (Flip (..))
+import Data.Bifunctor (Bifunctor (..))
+import Data.Bifunctor.Biff (Biff (..))
+import Data.Bifunctor.Flip (Flip (..))
import Data.Bifunctor.Product (Product (..))
-import Data.Bifunctor.Sum (Sum (..))
-import Data.Bifunctor.Tannen (Tannen (..))
-import Data.Bifunctor.Biff (Biff (..))
+import Data.Bifunctor.Sum (Sum (..))
+import Data.Bifunctor.Tannen (Tannen (..))
import qualified Data.Tuple