distributive-0.1: Haskell 98 Distributive functors -- Dual to Traversable

MaintainerEdward Kmett <ekmett@gmail.com>






class Functor g => Distributive g whereSource

This is the categorical dual of Traversable. However, there appears to be little benefit to allow the distribution via an arbitrary comonad so we restrict ourselves to Functor.

Minimal complete definition: distribute or collect

To be distributable a container will need to have a way to consistently zip a potentially infinite number of copies of itself. This effectively means that the holes in all values of that type, must have the same cardinality, fixed sized vectors, infinite streams, functions, etc. and no extra information to try to merge together.


distribute :: Functor f => f (g a) -> g (f a)Source

The dual of Data.Traversable.sequence

 distribute = collect id

collect :: Functor f => (a -> g b) -> f a -> g (f b)Source

 collect   = distribute . fmap f

distributeM :: Monad m => m (g a) -> g (m a)Source

 distributeM = fmap unwrapMonad . distribute . WrapMonad

collectM :: Monad m => (a -> g b) -> m a -> g (m b)Source

 collectM = distributeM . liftM f

fmapDefault :: Distributive g => (a -> b) -> g a -> g bSource

Every Distributive is a Functor. This is a valid default definition.

cotraverse :: (Functor f, Distributive g) => (f a -> b) -> f (g a) -> g bSource

comapM :: (Monad m, Distributive g) => (m a -> b) -> m (g a) -> g bSource