profunctors 5.0.1 → 5.1
raw patch · 5 files changed
+58/−6 lines, 5 files
Files
- CHANGELOG.markdown +6/−0
- profunctors.cabal +1/−1
- src/Data/Profunctor.hs +34/−3
- src/Data/Profunctor/Composition.hs +4/−0
- src/Data/Profunctor/Rep.hs +13/−2
CHANGELOG.markdown view
@@ -1,3 +1,9 @@+5.1+---+* `instance Costrong (Cokleisli f)`.+* `instance Cochoice (Star f)`.+* Changed the instance for `Cochoice (Costar f)`.+ 5.0.1 ----- * MINIMAL pragma for `Costrong` and `Cochoice`.
profunctors.cabal view
@@ -1,6 +1,6 @@ name: profunctors category: Control, Categories-version: 5.0.1+version: 5.1 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE
src/Data/Profunctor.hs view
@@ -301,7 +301,7 @@ -- | The generalization of 'Costar' of 'Functor' that is strong with respect -- to 'Either'. ----- Note: This is also a notion of strength, except with regards to another monoidal +-- Note: This is also a notion of strength, except with regards to another monoidal -- structure that we can choose to equip Hask with: the cocartesian coproduct. class Profunctor p => Choice p where left' :: p a b -> p (Either a c) (Either b c)@@ -328,9 +328,9 @@ {-# INLINE right' #-} instance Applicative f => Choice (Star f) where- left' (Star f) = Star $ either (fmap Left . f) (fmap Right . pure)+ left' (Star f) = Star $ either (fmap Left . f) (pure . Right) {-# INLINE left' #-}- right' (Star f) = Star $ either (fmap Left . pure) (fmap Right . f)+ right' (Star f) = Star $ either (pure . Left) (fmap Right . f) {-# INLINE right' #-} -- | 'extract' approximates 'costrength'@@ -377,10 +377,20 @@ unsecond :: p (d, a) (d, b) -> p a b unsecond = unfirst . dimap swap swap +#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 708+ {-# MINIMAL unfirst | unsecond #-}+#endif+ instance Costrong (->) where unfirst f a = b where (b, d) = f (a, d) unsecond f a = b where (d, b) = f (d, a) +instance Functor f => Costrong (Costar f) where+ unfirst (Costar f) = Costar f'+ where f' fa = b where (b, d) = f ((\a -> (a, d)) <$> fa)+ unsecond (Costar f) = Costar f'+ where f' fa = b where (d, b) = f ((,) d <$> fa)+ instance Costrong Tagged where unfirst (Tagged bd) = Tagged (fst bd) unsecond (Tagged db) = Tagged (snd db)@@ -392,6 +402,10 @@ unfirst (Kleisli f) = Kleisli (liftM fst . mfix . f') where f' x y = f (x, snd y) +instance Functor f => Costrong (Cokleisli f) where+ unfirst (Cokleisli f) = Cokleisli f'+ where f' fa = b where (b, d) = f ((\a -> (a, d)) <$> fa)+ -------------------------------------------------------------------------------- -- * Costrength for Either --------------------------------------------------------------------------------@@ -402,3 +416,20 @@ unright :: p (Either d a) (Either d b) -> p a b unright = unleft . dimap (either Right Left) (either Right Left)++#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 708+ {-# MINIMAL unleft | unright #-}+#endif++instance Cochoice (->) where+ unleft f = go . Left where go = either id (go . Right) . f+ unright f = go . Right where go = either (go . Left) id . f++instance Applicative f => Cochoice (Costar f) where+ unleft (Costar f) = Costar (go . fmap Left)+ where go = either id (go . pure . Right) . f++-- NB: Another instance that's highly questionable+instance Traversable f => Cochoice (Star f) where+ unright (Star f) = Star (go . Right)+ where go = either (go . Left) id . sequence . f
src/Data/Profunctor/Composition.hs view
@@ -127,6 +127,10 @@ closed (Procompose x y) = Procompose (closed x) (closed y) {-# INLINE closed #-} +instance (Corepresentable p, Corepresentable q) => Costrong (Procompose p q) where+ unfirst = unfirstCorep+ unsecond = unsecondCorep+ -- * Lax identity -- | @(->)@ functions as a lax identity for 'Profunctor' composition.
src/Data/Profunctor/Rep.hs view
@@ -27,6 +27,7 @@ -- * Corepresentable Profunctors , Corepresentable(..) , cotabulated+ , unfirstCorep, unsecondCorep ) where import Control.Applicative@@ -68,7 +69,7 @@ type Rep (Star f) = f tabulate = Star {-# INLINE tabulate #-}- + instance Representable (Forget r) where type Rep (Forget r) = Const r tabulate = Forget . (getConst .)@@ -89,9 +90,19 @@ -- | A 'Profunctor' @p@ is 'Corepresentable' if there exists a 'Functor' @f@ such that -- @p d c@ is isomorphic to @f d -> c@.-class Cosieve p (Corep p) => Corepresentable p where+class (Cosieve p (Corep p), Costrong p) => Corepresentable p where type Corep p :: * -> * cotabulate :: (Corep p d -> c) -> p d c++-- | Default definition for 'unfirst' given that p is 'Corepresentable'.+unfirstCorep :: Corepresentable p => p (a, d) (b, d) -> p a b+unfirstCorep p = cotabulate f+ where f fa = b where (b, d) = cosieve p ((\a -> (a, d)) <$> fa)++-- | Default definition for 'unsecond' given that p is 'Corepresentable'.+unsecondCorep :: Corepresentable p => p (d, a) (d, b) -> p a b+unsecondCorep p = cotabulate f+ where f fa = b where (d, b) = cosieve p ((,) d <$> fa) instance Corepresentable (->) where type Corep (->) = Identity