profunctor-extras 3.2.1 → 3.3
raw patch · 5 files changed
+61/−16 lines, 5 filesdep ~profunctors
Dependency ranges changed: profunctors
Files
- profunctor-extras.cabal +2/−2
- src/Data/Profunctor/Collage.hs +1/−1
- src/Data/Profunctor/Composition.hs +39/−10
- src/Data/Profunctor/Rep.hs +18/−2
- src/Data/Profunctor/Trace.hs +1/−1
profunctor-extras.cabal view
@@ -1,6 +1,6 @@ name: profunctor-extras category: Control, Categories-version: 3.2.1+version: 3.3 license: BSD3 cabal-version: >= 1.6 license-file: LICENSE@@ -41,7 +41,7 @@ comonad >= 3, semigroupoids >= 3, semigroupoid-extras >= 3,- profunctors >= 3.1.2,+ profunctors >= 3.2, tagged >= 0.4.4, transformers >= 0.2 && < 0.4
src/Data/Profunctor/Collage.hs view
@@ -23,7 +23,7 @@ import Data.Semigroupoid.Coproduct (L, R) import Data.Profunctor --- | The cograph of a profunctor+-- | The cograph of a 'Profunctor'. data Collage k b a where L :: (b -> b') -> Collage k (L b) (L b') R :: (a -> a') -> Collage k (R a) (R a')
src/Data/Profunctor/Composition.hs view
@@ -37,9 +37,10 @@ -- * Profunctor Composition --- | @'Procompose' p q@ is the 'Profunctor' composition of the profunctors @p@ and @q@.+-- | @'Procompose' p q@ is the 'Profunctor' composition of the+-- 'Profunctor's @p@ and @q@. ----- For a good explanation of profunctor composition in Haskell+-- For a good explanation of 'Profunctor' composition in Haskell -- see Dan Piponi's article: -- -- <http://blog.sigfpe.com/2011/07/profunctors-in-haskell.html>@@ -47,28 +48,53 @@ Procompose :: p d a -> q a c -> Procompose p q d c instance (Profunctor p, Profunctor q) => Profunctor (Procompose p q) where+ dimap l r (Procompose f g) = Procompose (lmap l f) (rmap r g)+ {-# INLINE dimap #-} lmap k (Procompose f g) = Procompose (lmap k f) g+ {-# INLINE rmap #-} rmap k (Procompose f g) = Procompose f (rmap k g)+ {-# INLINE lmap #-} k #. Procompose f g = Procompose f (k #. g)+ {-# INLINE ( #. ) #-} Procompose f g .# k = Procompose (f .# k) g+ {-# INLINE ( .# ) #-} instance Profunctor q => Functor (Procompose p q a) where fmap k (Procompose f g) = Procompose f (rmap k g)+ {-# INLINE fmap #-} --- | The composition of two representable profunctors is representable by the composition of their representations.+-- | The composition of two 'Representable' 'Profunctor's is 'Representable' by+-- the composition of their representations. instance (Representable p, Representable q) => Representable (Procompose p q) where type Rep (Procompose p q) = Compose (Rep p) (Rep q) tabulate f = Procompose (tabulate (getCompose . f)) (tabulate id)+ {-# INLINE tabulate #-} rep (Procompose f g) d = Compose $ rep g <$> rep f d+ {-# INLINE rep #-} instance (Corepresentable p, Corepresentable q) => Corepresentable (Procompose p q) where type Corep (Procompose p q) = Compose (Corep q) (Corep p) cotabulate f = Procompose (cotabulate id) (cotabulate (f . Compose))+ {-# INLINE cotabulate #-} corep (Procompose f g) (Compose d) = corep g $ corep f <$> d+ {-# INLINE corep #-} +instance (Strong p, Strong q) => Strong (Procompose p q) where+ first' (Procompose x y) = Procompose (first' x) (first' y)+ {-# INLINE first' #-}+ second' (Procompose x y) = Procompose (second' x) (second' y)+ {-# INLINE second' #-}++instance (Choice p, Choice q) => Choice (Procompose p q) where+ left' (Procompose x y) = Procompose (left' x) (left' y)+ {-# INLINE left' #-}+ right' (Procompose x y) = Procompose (right' x) (right' y)+ {-# INLINE right' #-}++ -- * Lax identity --- | @(->)@ functions as a lax identity for profunctor composition.+-- | @(->)@ functions as a lax identity for 'Profunctor' composition. -- -- This provides an 'Iso' for the @lens@ package that witnesses the -- isomorphism between @'Procompose' (->) q d c@ and @q d c@, which@@ -81,7 +107,7 @@ => p (q d c) (f (r d' c')) -> p (Procompose (->) q d c) (f (Procompose (->) r d' c')) idl = dimap (\(Procompose f g) -> lmap f g) (fmap (Procompose id)) --- | @(->)@ functions as a lax identity for profunctor composition.+-- | @(->)@ functions as a lax identity for 'Profunctor' composition. -- -- This provides an 'Iso' for the @lens@ package that witnesses the -- isomorphism between @'Procompose' q (->) d c@ and @q d c@, which@@ -94,9 +120,10 @@ => p (q d c) (f (r d' c')) -> p (Procompose q (->) d c) (f (Procompose r (->) d' c')) idr = dimap (\(Procompose f g) -> rmap g f) (fmap (`Procompose` id)) --- | Profunctor composition generalizes functor composition in two ways.+-- | 'Profunctor' composition generalizes 'Functor' composition in two ways. ----- This is the first, which shows that @exists b. (a -> f b, b -> g c)@ is isomorphic to @a -> f (g c)@.+-- This is the first, which shows that @exists b. (a -> f b, b -> g c)@ is+-- isomorphic to @a -> f (g c)@. -- -- @'upstars' :: 'Functor' f => Iso' ('Procompose' ('UpStar' f) ('UpStar' g) d c) ('UpStar' ('Compose' f g) d c)@ upstars :: (Profunctor p, Functor f, Functor h)@@ -106,9 +133,10 @@ hither (Procompose (UpStar dfx) (UpStar xgc)) = UpStar (Compose . fmap xgc . dfx) yon (UpStar dfgc) = Procompose (UpStar (getCompose . dfgc)) (UpStar id) --- | Profunctor composition generalizes functor composition in two ways.+-- | 'Profunctor' composition generalizes 'Functor' composition in two ways. ----- This is the second, which shows that @exists b. (f a -> b, g b -> c)@ is isomorphic to @g (f a) -> c@.+-- This is the second, which shows that @exists b. (f a -> b, g b -> c)@ is+-- isomorphic to @g (f a) -> c@. -- -- @'downstars' :: 'Functor' f => Iso' ('Procompose' ('DownStar' f) ('DownStar' g) d c) ('DownStar' ('Compose' g f) d c)@ downstars :: (Profunctor p, Functor g, Functor h)@@ -128,7 +156,8 @@ hither (Procompose (Kleisli dfx) (Kleisli xgc)) = Kleisli (Compose . liftM xgc . dfx) yon (Kleisli dfgc) = Procompose (Kleisli (getCompose . dfgc)) (Kleisli id) --- | This is a variant on 'downstars' that uses 'Cokleisli' instead of 'DownStar'.+-- | This is a variant on 'downstars' that uses 'Cokleisli' instead+-- of 'DownStar'. -- -- @'cokleislis' :: 'Functor' f => Iso' ('Procompose' ('Cokleisli' f) ('Cokleisli' g) d c) ('Cokleisli' ('Compose' g f) d c)@ cokleislis :: (Profunctor p, Functor g, Functor h)
src/Data/Profunctor/Rep.hs view
@@ -30,7 +30,7 @@ -- * Representable Profunctors --- | A 'Profunctor' @p@ is representable if there exists a 'Functor' @f@ such that+-- | A 'Profunctor' @p@ is 'Representable' if there exists a 'Functor' @f@ such that -- @p d c@ is isomorphic to @d -> f c@. class (Functor (Rep p), Profunctor p) => Representable p where type Rep p :: * -> *@@ -40,17 +40,23 @@ instance Representable (->) where type Rep (->) = Identity tabulate f = runIdentity . f+ {-# INLINE tabulate #-} rep f = Identity . f+ {-# INLINE rep #-} instance (Monad m, Functor m) => Representable (Kleisli m) where type Rep (Kleisli m) = m tabulate = Kleisli+ {-# INLINE tabulate #-} rep = runKleisli+ {-# INLINE rep #-} instance Functor f => Representable (UpStar f) where type Rep (UpStar f) = f tabulate = UpStar+ {-# INLINE tabulate #-} rep = runUpStar+ {-# INLINE rep #-} -- | 'tabulate' and 'rep' form two halves of an isomorphism. --@@ -61,10 +67,11 @@ => r (p d c) (f (q d' c')) -> r (d -> Rep p c) (f (d' -> Rep q c')) tabulated = dimap tabulate (fmap rep)+{-# INLINE tabulated #-} -- * Corepresentable Profunctors --- | A 'Profunctor' @p@ is corepresentable if there exists a 'Functor' @f@ such that+-- | A 'Profunctor' @p@ is 'Corepresentable' if there exists a 'Functor' @f@ such that -- @p d c@ is isomorphic to @f d -> c@. class (Functor (Corep p), Profunctor p) => Corepresentable p where type Corep p :: * -> *@@ -74,22 +81,30 @@ instance Corepresentable (->) where type Corep (->) = Identity cotabulate f = f . Identity+ {-# INLINE cotabulate #-} corep f (Identity d) = f d+ {-# INLINE corep #-} instance Functor w => Corepresentable (Cokleisli w) where type Corep (Cokleisli w) = w cotabulate = Cokleisli+ {-# INLINE cotabulate #-} corep = runCokleisli+ {-# INLINE corep #-} instance Corepresentable Tagged where type Corep Tagged = Proxy cotabulate f = Tagged (f Proxy)+ {-# INLINE cotabulate #-} corep (Tagged a) _ = a+ {-# INLINE corep #-} instance Functor f => Corepresentable (DownStar f) where type Corep (DownStar f) = f cotabulate = DownStar+ {-# INLINE cotabulate #-} corep = runDownStar+ {-# INLINE corep #-} -- | 'cotabulate' and 'corep' form two halves of an isomorphism. --@@ -100,3 +115,4 @@ => r (p d c) (h (q d' c')) -> r (Corep p d -> c) (h (Corep q d' -> c')) cotabulated = dimap cotabulate (fmap corep)+{-# INLINE cotabulated #-}
src/Data/Profunctor/Trace.hs view
@@ -14,6 +14,6 @@ ( Trace(..) ) where --- | Coend of 'Data.Profunctor.Profunctor' from @Hask -> Hask@+-- | Coend of 'Data.Profunctor.Profunctor' from @Hask -> Hask@. data Trace f where Trace :: f a a -> Trace f