{-# 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 Liftpqab = Lift { runLift :: forall x. pbx -> qax }
instance (Profunctor p, Profunctor q) =>Profunctor (Liftpq) where
dimapcabdf = Lift (lmapca.runLiftf.lmapbd)
{-# INLINE dimap #-}lmapcaf = Lift (lmapca.runLiftf)
{-# INLINE lmap #-}rmapbdf = Lift (runLiftf.lmapbd)
{-# INLINE rmap #-}bd#.f = Lift (\p -> runLiftf (p.#bd))
{-# INLINE ( #. ) #-}f.#ca = Lift (\p -> runLiftfp.#ca)
{-# INLINE (.#) #-}
instance Profunctor p =>Functor (Liftpqa) where
fmapbdf = Lift (runLiftf.lmapbd)
{-# 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 (Liftpq) where
id = Liftid{-# INLINE id #-}Liftf.Liftg = 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 (Liftpq) pab -> qabdecomposeLift (Procompose (Liftpq) p) = pqp{-# INLINE decomposeLift #-}