pipes-3.3.0: Compositional pipelines

Safe HaskellSafe-Inferred

Control.Proxy.Trans.Codensity

Contents

Description

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.

Synopsis

Codensity Proxy Transformer

data CodensityP p a' a b' b m r Source

The Codensity proxy transformer

Instances

ProxyTrans CodensityP 
PFunctor CodensityP 
MonadPlusP p => MonadPlusP (CodensityP p) 
Proxy p => ProxyInternal (CodensityP p) 
Proxy p => Proxy (CodensityP p) 
Proxy p => MFunctor (CodensityP p a' a b' b) 
Proxy p => MonadTrans (CodensityP p a' a b' b) 
(Monad m, Proxy p) => Monad (CodensityP p a' a b' b m) 
(Monad m, Proxy p) => Functor (CodensityP p a' a b' b m) 
(Monad m, MonadPlusP p) => MonadPlus (CodensityP p a' a b' b m) 
(Monad m, Proxy p) => Applicative (CodensityP p a' a b' b m) 
(Monad m, MonadPlusP p) => Alternative (CodensityP p a' a b' b m) 
(MonadIO m, Proxy p) => 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