Copyright  (C) 20082016 Edward Kmett 

License  BSDstyle (see the file LICENSE) 
Maintainer  Edward Kmett <ekmett@gmail.com> 
Stability  provisional 
Portability  nonportable (rank2 polymorphism) 
Safe Haskell  Trustworthy 
Language  Haskell98 
Synopsis
 newtype Codensity (m :: k > TYPE rep) a = Codensity {
 runCodensity :: forall b. (a > m b) > m b
 lowerCodensity :: Applicative f => Codensity f a > f a
 codensityToAdjunction :: Adjunction f g => Codensity g a > g (f a)
 adjunctionToCodensity :: Adjunction f g => g (f a) > Codensity g a
 codensityToRan :: Codensity g a > Ran g g a
 ranToCodensity :: Ran g g a > Codensity g a
 codensityToComposedRep :: Representable u => Codensity u a > u (Rep u, a)
 composedRepToCodensity :: Representable u => u (Rep u, a) > Codensity u a
 wrapCodensity :: (forall a. m a > m a) > Codensity m ()
 improve :: Functor f => (forall m. MonadFree f m => m a) > Free f a
Documentation
newtype Codensity (m :: k > TYPE rep) a #
is the Monad generated by taking the right Kan extension
of any Codensity
fFunctor
f
along itself (Ran f f
).
This can often be more "efficient" to construct than f
itself using
repeated applications of (>>=)
.
See "Asymptotic Improvement of Computations over Free Monads" by Janis Voigtländer for more information about this type.
https://www.janisvoigtlaender.eu/papers/AsymptoticImprovementOfComputationsOverFreeMonads.pdf
Codensity  

Instances
MonadReader r m => MonadReader r (Codensity m) #  
MonadReader r m => MonadState r (Codensity m) #  
(Functor f, MonadFree f m) => MonadFree f (Codensity m) #  
Defined in Control.Monad.Codensity  
MonadTrans (Codensity :: (Type > Type) > Type > Type) #  
Defined in Control.Monad.Codensity  
Monad (Codensity f) #  
Functor (Codensity k) #  
MonadFail f => MonadFail (Codensity f) #  
Defined in Control.Monad.Codensity  
Applicative (Codensity f) #  
Defined in Control.Monad.Codensity  
MonadIO m => MonadIO (Codensity m) #  
Defined in Control.Monad.Codensity  
Alternative v => Alternative (Codensity v) #  
Alternative v => MonadPlus (Codensity v) #  
Plus v => Plus (Codensity v) #  
Defined in Control.Monad.Codensity  
Alt v => Alt (Codensity v) #  
Apply (Codensity f) #  
lowerCodensity :: Applicative f => Codensity f a > f a #
This serves as the *left*inverse (retraction) of lift
.
lowerCodensity
.lift
≡id
In general this is not a full 2sided inverse, merely a retraction, as
is often considerably "larger" than Codensity
mm
.
e.g.
could support a full complement of Codensity
((>) s)) a ~ forall r. (a > s > r) > s > r
actions, while MonadState
s(>) s
is limited to
actions.MonadReader
s
codensityToAdjunction :: Adjunction f g => Codensity g a > g (f a) #
The Codensity
monad of a right adjoint is isomorphic to the
monad obtained from the Adjunction
.
codensityToAdjunction
.adjunctionToCodensity
≡id
adjunctionToCodensity
.codensityToAdjunction
≡id
adjunctionToCodensity :: Adjunction f g => g (f a) > Codensity g a #
codensityToRan :: Codensity g a > Ran g g a #
The Codensity
Monad
of a Functor
g
is the right Kan extension (Ran
)
of g
along itself.
codensityToRan
.ranToCodensity
≡id
ranToCodensity
.codensityToRan
≡id
ranToCodensity :: Ran g g a > Codensity g a #
codensityToComposedRep :: Representable u => Codensity u a > u (Rep u, a) #
The Codensity
monad of a representable Functor
is isomorphic to the
monad obtained from the Adjunction
for which that Functor
is the right
adjoint.
codensityToComposedRep
.composedRepToCodensity
≡id
composedRepToCodensity
.codensityToComposedRep
≡id
codensityToComposedRep =ranToComposedRep
.codensityToRan
composedRepToCodensity :: Representable u => u (Rep u, a) > Codensity u a #
wrapCodensity :: (forall a. m a > m a) > Codensity m () #
Wrap the remainder of the Codensity
action using the given
function.
This function can be used to register cleanup actions that will be executed at the end. Example:
wrapCodensity (`finally` putStrLn "Done.")
improve :: Functor f => (forall m. MonadFree f m => m a) > Free f a #
Right associate all binds in a computation that generates a free monad
This can improve the asymptotic efficiency of the result, while preserving semantics.
See "Asymptotic Improvement of Computations over Free Monads" by Janis Voightländer for more information about this combinator.