#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
#endif
module Data.Profunctor.Codensity
( Codensity(..)
, decomposeCodensity
) where
import Control.Category
import Data.Profunctor.Unsafe
import Data.Profunctor.Composition
import Prelude hiding (id,(.))
newtype Codensity p a b = Codensity { runCodensity :: forall x. p x a -> p x b }
instance Profunctor p => Profunctor (Codensity p) where
dimap ca bd f = Codensity (rmap bd . runCodensity f . rmap ca)
lmap ca f = Codensity (runCodensity f . rmap ca)
rmap bd f = Codensity (rmap bd . runCodensity f)
bd #. f = Codensity (\p -> bd #. runCodensity f p)
f .# ca = Codensity (\p -> runCodensity f (ca #. p))
instance Profunctor p => Functor (Codensity p a) where
fmap bd f = Codensity (rmap bd . runCodensity f)
instance Category (Codensity p) where
id = Codensity id
Codensity f . Codensity g = Codensity (f . g)
decomposeCodensity :: Procompose (Codensity p) p a b -> p a b
decomposeCodensity (Procompose (Codensity pp) p) = pp p