Safe Haskell | Safe-Inferred |
---|
This module provides the proxy transformer equivalent of CodensityT
.
The base Proxy
implementations suffer a quadratic time complexity if
you repeatedly left-associate the monad bind operation. You can recover
linear time complexity just by adding runCodensityK
right after
runProxy
, which transforms the base Proxy
implementation to use
continuation-passing style:
-- Before: runProxy $ ... -- After: runProxy $ runCodensityK $ ...
Everything will still type-check if you you wrote your code to be
polymorphic over the base Proxy
.
Note that even though CodensityP
has better time complexity for
left-associated binds, it has worse constant factors for everything else
(about 6x slower on pure benchmarks), because:
- You cannot optimize it using rewrite rules
- It has a slower composition operation
So only use it if you actually need it, which is typically only the case if
you left associate your monad binds on the order of hundreds of times. Even
better: only wrap the problematic portions of the pipeline in
runCodensityK
so that the performance of the rest of the pipeline does not
suffer.
- data CodensityP p a' a b' b m r
- runCodensityP :: (Monad m, Proxy p) => CodensityP p a' a b' b m r -> p a' a b' b m r
- runCodensityK :: (Monad m, Proxy p) => (q -> CodensityP p a' a b' b m r) -> q -> p a' a b' b m r
Codensity Proxy Transformer
data CodensityP p a' a b' b m r Source
The Codensity
proxy transformer
ProxyTrans CodensityP | |
PFunctor CodensityP | |
MonadPlusP p => MonadPlusP (CodensityP p) | |
Proxy p => ProxyInternal (CodensityP p) | |
Proxy p => Proxy (CodensityP p) | |
ListT p => ListT (CodensityP p) | |
Proxy p => MFunctor (CodensityP p a' a b' b) | |
Proxy p => MonadTrans (CodensityP p a' a b' b) | |
(Proxy p, Monad m) => Monad (CodensityP p a' a b' b m) | |
(Proxy p, Monad m) => Functor (CodensityP p a' a b' b m) | |
(MonadPlusP p, Monad m) => MonadPlus (CodensityP p a' a b' b m) | |
(Proxy p, Monad m) => Applicative (CodensityP p a' a b' b m) | |
(MonadPlusP p, Monad m) => Alternative (CodensityP p a' a b' b m) | |
(Proxy p, MonadIO m) => MonadIO (CodensityP p a' a b' b m) |
runCodensityP :: (Monad m, Proxy p) => CodensityP p a' a b' b m r -> p a' a b' b m rSource
Run a CodensityP
proxy, converting, converting it back to the base proxy
runCodensityK :: (Monad m, Proxy p) => (q -> CodensityP p a' a b' b m r) -> q -> p a' a b' b m rSource
Run a CodensityP
'K
'leisli arrow, converting it back to the base proxy