adjunctions 4.0.3 → 4.1.0.1
raw patch · 6 files changed
+63/−6 lines, 6 filesdep +profunctorsdep ~mtldep ~transformers
Dependencies added: profunctors
Dependency ranges changed: mtl, transformers
Files
- .travis.yml +6/−2
- adjunctions.cabal +4/−3
- src/Data/Functor/Adjunction.hs +12/−0
- src/Data/Functor/Contravariant/Adjunction.hs +12/−0
- src/Data/Functor/Contravariant/Rep.hs +15/−0
- src/Data/Functor/Rep.hs +14/−1
.travis.yml view
@@ -7,13 +7,17 @@ # Try installing some of the build-deps with apt-get for speed. - travis/cabal-apt-install $mode+ - travis/cabal-apt-install packdeps packunused install: - cabal configure $mode- - cabal build+ - cabal build --ghc-options=-ddump-minimal-imports script:- - $script && hlint src --cpp-define HLINT+ - $script+ - hlint src --cpp-define HLINT+ - packdeps adjunctions.cabal+ - packunused notifications: irc:
adjunctions.cabal view
@@ -1,6 +1,6 @@ name: adjunctions category: Data Structures, Adjunctions-version: 4.0.3+version: 4.1.0.1 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -47,11 +47,12 @@ contravariant >= 0.4.1 && < 1, distributive >= 0.4 && < 1, free >= 4 && < 5,- mtl >= 2.0.1 && < 2.2,+ mtl >= 2.0.1 && < 2.3,+ profunctors >= 4 && < 5, tagged >= 0.7 && < 1, semigroupoids >= 4 && < 5, semigroups >= 0.11 && < 1,- transformers >= 0.2 && < 0.4,+ transformers >= 0.2 && < 0.5, void >= 0.5.5.1 && < 1 exposed-modules:
src/Data/Functor/Adjunction.hs view
@@ -20,6 +20,7 @@ ------------------------------------------------------------------------------------------- module Data.Functor.Adjunction ( Adjunction(..)+ , adjuncted , tabulateAdjunction , indexAdjunction , zapWithAdjunction@@ -49,6 +50,7 @@ import Data.Functor.Compose import Data.Functor.Product import Data.Functor.Rep+import Data.Profunctor import Data.Void -- | An adjunction between Hask and Hask.@@ -79,6 +81,16 @@ counit = rightAdjunct id leftAdjunct f = fmap f . unit rightAdjunct f = counit . fmap f++-- | 'leftAdjunct' and 'rightAdjunct' form two halves of an isomorphism.+--+-- This can be used with the combinators from the @lens@ package.+--+-- @'adjuncted' :: 'Adjunction' f u => 'Iso'' (f a -> b) (a -> u b)@+adjuncted :: (Adjunction f u, Profunctor p, Functor g) + => p (a -> u b) (g (c -> u d)) -> p (f a -> b) (g (f c -> d))+adjuncted = dimap leftAdjunct (fmap rightAdjunct)+{-# INLINE adjuncted #-} -- | Every right adjoint is representable by its left adjoint -- applied to a unit element
src/Data/Functor/Contravariant/Adjunction.hs view
@@ -16,6 +16,7 @@ module Data.Functor.Contravariant.Adjunction ( Adjunction(..)+ , adjuncted , contrarepAdjunction , coindexAdjunction ) where@@ -25,6 +26,7 @@ #endif import Data.Functor.Contravariant import Data.Functor.Contravariant.Rep+import Data.Profunctor -- | An adjunction from @Hask^op@ to @Hask@ --@@ -48,6 +50,16 @@ counit = rightAdjunct id leftAdjunct f = contramap f . unit rightAdjunct f = contramap f . counit++-- | 'leftAdjunct' and 'rightAdjunct' form two halves of an isomorphism.+--+-- This can be used with the combinators from the @lens@ package.+--+-- @'adjuncted' :: 'Adjunction' f g => 'Iso'' (b -> f a) (a -> g b)@+adjuncted :: (Adjunction f g, Profunctor p, Functor h) + => p (a -> g b) (h (c -> g d)) -> p (b -> f a) (h (d -> f c))+adjuncted = dimap leftAdjunct (fmap rightAdjunct)+{-# INLINE adjuncted #-} -- | This 'Adjunction' gives rise to the @Cont@ 'Monad' instance Adjunction (Op r) (Op r) where
src/Data/Functor/Contravariant/Rep.hs view
@@ -16,6 +16,7 @@ ( -- * Representable Contravariant Functors Representable(..)+ , tabulated -- * Default definitions , contramapRep ) where@@ -24,6 +25,7 @@ import Data.Functor.Contravariant import Data.Functor.Contravariant.Day import Data.Functor.Product+import Data.Profunctor import Data.Proxy import Prelude hiding (lookup) @@ -49,6 +51,19 @@ -- @ contramapWithRep :: (b -> Either a (Rep f)) -> f a -> f b contramapWithRep f p = tabulate $ either (index p) id . f++{-# RULES+"tabulate/index" forall t. tabulate (index t) = t #-}++-- | 'tabulate' and 'index' form two halves of an isomorphism.+--+-- This can be used with the combinators from the @lens@ package.+--+-- @'tabulated' :: 'Representable' f => 'Iso'' (a -> 'Rep' f) (f a)@+tabulated :: (Representable f, Representable g, Profunctor p, Functor h) + => p (f a) (h (g b)) -> p (a -> Rep f) (h (b -> Rep g))+tabulated = dimap tabulate (fmap index)+{-# INLINE tabulated #-} contramapRep :: Representable f => (a -> b) -> f b -> f a contramapRep f = tabulate . (. f) . index
src/Data/Functor/Rep.hs view
@@ -23,6 +23,7 @@ ( -- * Representable Functors Representable(..)+ , tabulated -- * Wrapped representable functors , Co(..) -- * Default definitions@@ -59,6 +60,7 @@ ) where import Control.Applicative+import Control.Arrow ((&&&)) import Control.Comonad import Control.Comonad.Trans.Class import Control.Comonad.Trans.Traced@@ -71,6 +73,7 @@ import Data.Functor.Compose import Data.Functor.Extend import Data.Functor.Product+import Data.Profunctor import Data.Proxy import Data.Sequence (Seq) import qualified Data.Sequence as Seq@@ -103,6 +106,16 @@ {-# RULES "tabulate/index" forall t. tabulate (index t) = t #-} +-- | 'tabulate' and 'index' form two halves of an isomorphism.+--+-- This can be used with the combinators from the @lens@ package.+--+-- @'tabulated' :: 'Representable' f => 'Iso'' ('Rep' f -> a) (f a)@+tabulated :: (Representable f, Representable g, Profunctor p, Functor h) + => p (f a) (h (g b)) -> p (Rep f -> a) (h (Rep g -> b))+tabulated = dimap tabulate (fmap index)+{-# INLINE tabulated #-}+ -- * Default definitions fmapRep :: Representable f => (a -> b) -> f a -> f b@@ -121,7 +134,7 @@ mzipWithRep f as bs = tabulate $ \k -> f (index as k) (index bs k) mzipRep :: Representable f => f a -> f b -> f (a, b)-mzipRep as bs = tabulate $ \k -> (index as k, index bs k)+mzipRep as bs = tabulate (index as &&& index bs) askRep :: Representable f => f (Rep f) askRep = tabulate id