profunctors 4.0.2 → 4.0.3
raw patch · 4 files changed
+67/−3 lines, 4 files
Files
- CHANGELOG.markdown +4/−0
- profunctors.cabal +2/−1
- src/Data/Profunctor/Lift.hs +59/−0
- src/Data/Profunctor/Rift.hs +2/−2
CHANGELOG.markdown view
@@ -1,3 +1,7 @@+4.0.3+-----+* Added `Data.Profunctor.Lift` containing the left Kan lift of a profunctor.+ 4.0.2 ----- * Added `assoc` to `Data.Profunctor.Composition` so that we have all 3 associators.
profunctors.cabal view
@@ -1,6 +1,6 @@ name: profunctors category: Control, Categories-version: 4.0.2+version: 4.0.3 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -37,6 +37,7 @@ Data.Profunctor Data.Profunctor.Composition Data.Profunctor.Collage+ Data.Profunctor.Lift Data.Profunctor.Rep Data.Profunctor.Rift Data.Profunctor.Trace
+ src/Data/Profunctor/Lift.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE TypeFamilies #-}+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Copyright : (C) 2014 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : Rank2Types, TFs+--+----------------------------------------------------------------------------+module Data.Profunctor.Lift+ ( Lift(..)+ , decomposeLift+ ) where++import Control.Category+import Data.Profunctor.Unsafe+import Data.Profunctor.Composition+import Prelude hiding (id,(.))++-- | This represents the left Kan lift of a 'Profunctor' @q@ along a 'Profunctor' @p@ in a limited version of the 2-category of Profunctors where the only object is the category Hask, 1-morphisms are profunctors composed and compose with Profunctor composition, and 2-morphisms are just natural transformations.+newtype Lift p q a b = Lift { runLift :: forall x. p b x -> q a x }+++instance (Profunctor p, Profunctor q) => Profunctor (Lift p q) where+ dimap ca bd f = Lift (lmap ca . runLift f . lmap bd)+ {-# INLINE dimap #-}+ lmap ca f = Lift (lmap ca . runLift f)+ {-# INLINE lmap #-}+ rmap bd f = Lift (runLift f . lmap bd)+ {-# INLINE rmap #-}+ bd #. f = Lift (\p -> runLift f (p .# bd))+ {-# INLINE ( #. ) #-}+ f .# ca = Lift (\p -> runLift f p .# ca)+ {-# INLINE (.#) #-}++instance Profunctor p => Functor (Lift p q a) where+ fmap bd f = Lift (runLift f . lmap bd)+ {-# INLINE fmap #-}++-- | @'Lift' p p@ forms a 'Monad' in the 'Profunctor' 2-category, which is isomorphic to a Haskell 'Category' instance.+instance p ~ q => Category (Lift p q) where+ id = Lift id+ {-# INLINE id #-}+ Lift f . Lift g = Lift (g . f)+ {-# INLINE (.) #-}++-- | The 2-morphism that defines a left Kan lift.+--+-- Note: When @p@ is right adjoint to @'Lift' p (->)@ then 'decomposeLift' is the 'counit' of the adjunction.+decomposeLift :: Procompose (Lift p q) p a b -> q a b+decomposeLift (Procompose (Lift pq) p) = pq p+{-# INLINE decomposeLift #-}
src/Data/Profunctor/Rift.hs view
@@ -11,7 +11,7 @@ -- -- Maintainer : Edward Kmett <ekmett@gmail.com> -- Stability : provisional--- Portability : Rank2Types+-- Portability : Rank2Types, TFs -- ---------------------------------------------------------------------------- module Data.Profunctor.Rift@@ -55,7 +55,7 @@ -- | The 2-morphism that defines a right Kan lift. ----- Note: When @f@ is left adjoint to @'Rift' f (->)@ then 'decomposeRift' is the 'counit' of the adjunction.+-- Note: When @q@ is left adjoint to @'Rift' q (->)@ then 'decomposeRift' is the 'counit' of the adjunction. decomposeRift :: Procompose q (Rift q p) a b -> p a b decomposeRift (Procompose q (Rift qp)) = qp q {-# INLINE decomposeRift #-}