assoc-1.1.1/0000755000000000000000000000000007346545000011013 5ustar0000000000000000assoc-1.1.1/CHANGELOG.md0000644000000000000000000000057207346545000012630 0ustar0000000000000000## 1.1.1 - Drop support for GHC prior GHC-8.6.5 ## 1.1 - Depend on `bifunctor-classes-compat` only. Instances for types defined in `bifunctors` package are moved there. With this change `assoc` only depends on `base` and `tagged`. - Mark modules as explicitly Safe ## 1.0.2 - Add 'Swap' instances for more n-tuples ## 1.0.1 - Add `Assoc Const` and `Tagged` instances assoc-1.1.1/LICENSE0000644000000000000000000000276207346545000012027 0ustar0000000000000000Copyright (c) 2017, Oleg Grenrus All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * Neither the name of Oleg Grenrus nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER 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. assoc-1.1.1/assoc.cabal0000644000000000000000000000254507346545000013115 0ustar0000000000000000cabal-version: 3.0 name: assoc version: 1.1.1 license: BSD-3-Clause license-file: LICENSE synopsis: swap and assoc: Symmetric and Semigroupy Bifunctors category: Data description: Provides generalisations of @swap :: (a,b) -> (b,a)@ and @assoc :: ((a,b),c) -> (a,(b,c))@ to @Bifunctor@s supporting similar operations (e.g. @Either@, @These@). author: Oleg Grenrus maintainer: Oleg Grenrus build-type: Simple extra-source-files: CHANGELOG.md tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.5 || ==9.8.2 || ==9.10.1 source-repository head type: git location: https://github.com/phadej/assoc.git flag tagged default: False manual: True description: You can disable the use of the `tagged` package using `-f-tagged`. . Disabing this is an unsupported configuration, but it may be useful for accelerating builds in sandboxes for expert users. library default-language: Haskell2010 hs-source-dirs: src build-depends: base >=4.12 && <4.21 if flag(tagged) build-depends: tagged >=0.8.8 && <0.9 exposed-modules: Data.Bifunctor.Assoc Data.Bifunctor.Swap other-extensions: TypeFamilies assoc-1.1.1/src/Data/Bifunctor/0000755000000000000000000000000007346545000014406 5ustar0000000000000000assoc-1.1.1/src/Data/Bifunctor/Assoc.hs0000644000000000000000000000652107346545000016016 0ustar0000000000000000{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >=704 {-# LANGUAGE Safe #-} #elif __GLASGOW_HASKELL__ >=702 {-# LANGUAGE Trustworthy #-} #endif module Data.Bifunctor.Assoc ( Assoc (..), ) where import Control.Applicative (Const (..)) import Data.Bifunctor (Bifunctor (..)) #ifdef MIN_VERSION_tagged import Data.Tagged (Tagged (..)) #endif -- | "Semigroup-y" 'Bifunctor's. -- -- @ -- 'assoc' . 'unassoc' = 'id' -- 'unassoc' . 'assoc' = 'id' -- 'assoc' . 'bimap' ('bimap' f g) h = 'bimap' f ('bimap' g h) . 'assoc' -- @ -- -- This library doesn't provide @Monoidal@ class, with left and right unitors. -- Are they useful in practice? -- class Bifunctor p => Assoc p where assoc :: p (p a b) c -> p a (p b c) unassoc :: p a (p b c) -> p (p a b) c instance Assoc (,) where assoc ((a, b), c) = (a, (b, c)) unassoc (a, (b, c)) = ((a, b), c) instance Assoc Either where assoc (Left (Left a)) = Left a assoc (Left (Right b)) = Right (Left b) assoc (Right c) = Right (Right c) unassoc (Left a) = Left (Left a) 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) #ifdef MIN_VERSION_tagged instance Assoc Tagged where assoc (Tagged a) = Tagged (Tagged a) unassoc (Tagged (Tagged a)) = Tagged a #endif -- $setup -- -- TODO: make proper test-suite -- -- >>> import Data.Proxy -- >>> import Test.QuickCheck -- >>> import Test.QuickCheck.Instances -- >>> import Data.Functor.Classes -- -- >>> :{ -- let assocUnassocLaw :: (Assoc p, Eq2 p) => Proxy p -> p Bool (p Int Char) -> Bool -- assocUnassocLaw _ x = liftEq2 (==) eq2 (assoc (unassoc x)) x -- :} -- -- >>> quickCheck $ assocUnassocLaw (Proxy :: Proxy (,)) -- +++ OK, passed 100 tests. -- -- >>> 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 -- :} -- -- >>> quickCheck $ unassocAssocLaw (Proxy :: Proxy (,)) -- +++ OK, passed 100 tests. -- -- >>> 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 -- -> p (p Int Char) Bool -- -> Bool -- bimapLaw _ (Fun _ f) (Fun _ g) (Fun _ h) x = liftEq2 (==) eq2 -- (assoc . bimap (bimap f g) h $ x) -- (bimap f (bimap g h) . assoc $ x) -- :} -- -- >>> quickCheck $ bimapLaw (Proxy :: Proxy (,)) -- +++ OK, passed 100 tests. -- -- >>> 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. assoc-1.1.1/src/Data/Bifunctor/Swap.hs0000644000000000000000000000242507346545000015657 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE TypeFamilies #-} #if __GLASGOW_HASKELL__ >=704 {-# LANGUAGE Safe #-} #elif __GLASGOW_HASKELL__ >=702 {-# LANGUAGE Trustworthy #-} #endif module Data.Bifunctor.Swap ( Swap (..), ) where import Data.Bifunctor (Bifunctor (..)) import qualified Data.Tuple -- | Symmetric 'Bifunctor's. -- -- @ -- 'swap' . 'swap' = 'id' -- @ -- -- If @p@ is a 'Bifunctor' the following property is assumed to hold: -- -- @ -- 'swap' . 'bimap' f g = 'bimap' g f . 'swap' -- @ -- -- 'Swap' isn't a subclass of 'Bifunctor', as for example -- -- >>> newtype Bipredicate a b = Bipredicate (a -> b -> Bool) -- -- is not a 'Bifunctor' but has 'Swap' instance -- -- >>> instance Swap Bipredicate where swap (Bipredicate p) = Bipredicate (flip p) -- class Swap p where swap :: p a b -> p b a instance Swap (,) where swap = Data.Tuple.swap instance Swap Either where swap (Left x) = Right x swap (Right x) = Left x instance Swap ((,,) x) where swap (x,a,b) = (x,b,a) instance Swap ((,,,) x y) where swap (x,y,a,b) = (x,y,b,a) instance Swap ((,,,,) x y z) where swap (x,y,z,a,b) = (x,y,z,b,a) instance Swap ((,,,,,) x y z w) where swap (x,y,z,w,a,b) = (x,y,z,w,b,a) instance Swap ((,,,,,,) x y z w v) where swap (x,y,z,w,v,a,b) = (x,y,z,w,v,b,a)