profunctors 4.0 → 4.0.1
raw patch · 3 files changed
+31/−23 lines, 3 files
Files
- profunctors.cabal +1/−1
- src/Data/Profunctor/Composition.hs +25/−16
- src/Data/Profunctor/Rep.hs +5/−6
profunctors.cabal view
@@ -1,6 +1,6 @@ name: profunctors category: Control, Categories-version: 4.0+version: 4.0.1 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE
src/Data/Profunctor/Composition.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeFamilies #-} #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE Trustworthy #-}@@ -38,6 +39,8 @@ import Data.Profunctor.Unsafe import Prelude hiding ((.),id) +type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)+ -- * Profunctor Composition -- | @'Procompose' p q@ is the 'Profunctor' composition of the@@ -111,8 +114,7 @@ -- @ -- 'idl' :: 'Profunctor' q => Iso' ('Procompose' (->) q d c) (q d c) -- @-idl :: (Profunctor p, Profunctor q, Functor f)- => p (q d c) (f (r d' c')) -> p (Procompose (->) q d c) (f (Procompose (->) r d' c'))+idl :: Profunctor q => Iso (Procompose (->) q d c) (Procompose (->) r d' c') (q d c) (r d' c') idl = dimap (\(Procompose f g) -> lmap f g) (fmap (Procompose id)) -- | @(->)@ functions as a lax identity for 'Profunctor' composition.@@ -124,8 +126,7 @@ -- @ -- 'idr' :: 'Profunctor' q => Iso' ('Procompose' q (->) d c) (q d c) -- @-idr :: (Profunctor p, Profunctor q, Functor f)- => p (q d c) (f (r d' c')) -> p (Procompose q (->) d c) (f (Procompose r (->) d' c'))+idr :: Profunctor q => Iso (Procompose q (->) d c) (Procompose r (->) d' c') (q d c) (r d' c') idr = dimap (\(Procompose f g) -> rmap g f) (fmap (`Procompose` id)) -- | 'Profunctor' composition generalizes 'Functor' composition in two ways.@@ -134,9 +135,11 @@ -- 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)- => p (UpStar (Compose f g) d c) (h (UpStar (Compose f' g') d' c'))- -> p (Procompose (UpStar f) (UpStar g) d c) (h (Procompose (UpStar f') (UpStar g') d' c'))+upstars :: Functor f+ => Iso (Procompose (UpStar f ) (UpStar g ) d c )+ (Procompose (UpStar f') (UpStar g') d' c')+ (UpStar (Compose f g ) d c )+ (UpStar (Compose f' g') d' c') upstars = dimap hither (fmap yon) where hither (Procompose (UpStar dfx) (UpStar xgc)) = UpStar (Compose . fmap xgc . dfx) yon (UpStar dfgc) = Procompose (UpStar (getCompose . dfgc)) (UpStar id)@@ -147,9 +150,11 @@ -- 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)- => p (DownStar (Compose g f) d c) (h (DownStar (Compose g' f') d' c'))- -> p (Procompose (DownStar f) (DownStar g) d c) (h (Procompose (DownStar f') (DownStar g') d' c'))+downstars :: Functor g+ => Iso (Procompose (DownStar f ) (DownStar g ) d c )+ (Procompose (DownStar f') (DownStar g') d' c')+ (DownStar (Compose g f ) d c )+ (DownStar (Compose g' f') d' c') downstars = dimap hither (fmap yon) where hither (Procompose (DownStar fdx) (DownStar gxc)) = DownStar (gxc . fmap fdx . getCompose) yon (DownStar dgfc) = Procompose (DownStar id) (DownStar (dgfc . Compose))@@ -157,9 +162,11 @@ -- | This is a variant on 'upstars' that uses 'Kleisli' instead of 'UpStar'. -- -- @'kleislis' :: 'Monad' f => Iso' ('Procompose' ('Kleisli' f) ('Kleisli' g) d c) ('Kleisli' ('Compose' f g) d c)@-kleislis :: (Profunctor p, Monad f, Functor h)- => p (Kleisli (Compose f g) d c) (h (Kleisli (Compose f' g') d' c'))- -> p (Procompose (Kleisli f) (Kleisli g) d c) (h (Procompose (Kleisli f') (Kleisli g') d' c'))+kleislis :: Monad f+ => Iso (Procompose (Kleisli f ) (Kleisli g ) d c )+ (Procompose (Kleisli f') (Kleisli g') d' c')+ (Kleisli (Compose f g ) d c )+ (Kleisli (Compose f' g') d' c') kleislis = dimap hither (fmap yon) where hither (Procompose (Kleisli dfx) (Kleisli xgc)) = Kleisli (Compose . liftM xgc . dfx) yon (Kleisli dfgc) = Procompose (Kleisli (getCompose . dfgc)) (Kleisli id)@@ -168,9 +175,11 @@ -- 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)- => p (Cokleisli (Compose g f) d c) (h (Cokleisli (Compose g' f') d' c'))- -> p (Procompose (Cokleisli f) (Cokleisli g) d c) (h (Procompose (Cokleisli f') (Cokleisli g') d' c'))+cokleislis :: Functor g+ => Iso (Procompose (Cokleisli f ) (Cokleisli g ) d c )+ (Procompose (Cokleisli f') (Cokleisli g') d' c')+ (Cokleisli (Compose g f ) d c )+ (Cokleisli (Compose g' f') d' c') cokleislis = dimap hither (fmap yon) where hither (Procompose (Cokleisli fdx) (Cokleisli gxc)) = Cokleisli (gxc . fmap fdx . getCompose) yon (Cokleisli dgfc) = Procompose (Cokleisli id) (Cokleisli (dgfc . Compose))
src/Data/Profunctor/Rep.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-}@@ -62,14 +63,14 @@ rep = runUpStar {-# INLINE rep #-} +type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)+ -- | 'tabulate' and 'rep' form two halves of an isomorphism. -- -- This can be used with the combinators from the @lens@ package. -- -- @'tabulated' :: 'Representable' p => 'Iso'' (d -> 'Rep' p c) (p d c)@-tabulated :: (Profunctor r, Functor f, Representable p, Representable q)- => r (p d c) (f (q d' c'))- -> r (d -> Rep p c) (f (d' -> Rep q c'))+tabulated :: (Representable p, Representable q) => Iso (d -> Rep p c) (d' -> Rep q c') (p d c) (q d' c') tabulated = dimap tabulate (fmap rep) {-# INLINE tabulated #-} @@ -115,8 +116,6 @@ -- This can be used with the combinators from the @lens@ package. -- -- @'tabulated' :: 'Corep' f p => 'Iso'' (f d -> c) (p d c)@-cotabulated :: (Profunctor r, Functor h, Corepresentable p, Corepresentable q)- => r (p d c) (h (q d' c'))- -> r (Corep p d -> c) (h (Corep q d' -> c'))+cotabulated :: (Corepresentable p, Corepresentable q) => Iso (Corep p d -> c) (Corep q d' -> c') (p d c) (q d' c') cotabulated = dimap cotabulate (fmap corep) {-# INLINE cotabulated #-}