Copyright | (C) 2011-2016 Edward Kmett |
---|---|

License | BSD-style (see the file LICENSE) |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Stability | provisional |

Portability | portable |

Safe Haskell | Trustworthy |

Language | Haskell98 |

- class Functor g => Distributive g where
- cotraverse :: (Distributive g, Functor f) => (f a -> b) -> f (g a) -> g b
- comapM :: (Distributive g, Monad m) => (m a -> b) -> m (g a) -> g b
- fmapCollect :: forall f a b. Distributive f => (a -> b) -> f a -> f b

# Documentation

class Functor g => Distributive g where #

This is the categorical dual of `Traversable`

.

Due to the lack of non-trivial comonoids in Haskell, we can restrict
ourselves to requiring a `Functor`

rather than
some Coapplicative class. Categorically every `Distributive`

functor is actually a right adjoint, and so it must be `Representable`

endofunctor and preserve all limits. This is a fancy way of saying it
isomorphic to `(->) x`

for some x.

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) #

The dual of `sequenceA`

`>>>`

[2,3]`distribute [(+1),(+2)] 1`

`distribute`

=`collect`

`id`

`distribute`

.`distribute`

=`id`

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

`collect`

f =`distribute`

.`fmap`

f`fmap`

f =`runIdentity`

.`collect`

(`Identity`

. f)`fmap`

`distribute`

.`collect`

f =`getCompose`

.`collect`

(`Compose`

. f)

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

The dual of `sequence`

`distributeM`

=`fmap`

`unwrapMonad`

.`distribute`

.`WrapMonad`

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

`collectM`

=`distributeM`

.`liftM`

f

Distributive U1 # | |

Distributive Par1 # | |

Distributive Identity # | |

Distributive Min # | |

Distributive Max # | |

Distributive First # | |

Distributive Last # | |

Distributive Complex # | |

Distributive Dual # | |

Distributive Sum # | |

Distributive Product # | |

Distributive ((->) e) # | |

Distributive f => Distributive (Rec1 f) # | |

Distributive (Proxy *) # | |

(Distributive a, Distributive b) => Distributive ((:*:) a b) # | |

(Distributive a, Distributive b) => Distributive ((:.:) a b) # | |

Distributive (Tagged * t) # | |

Distributive f => Distributive (Reverse * f) # | |

Distributive f => Distributive (Backwards * f) # | |

Distributive g => Distributive (IdentityT * g) # | |

Distributive f => Distributive (M1 i c f) # | |

(Distributive f, Distributive g) => Distributive (Product * f g) # | |

Distributive g => Distributive (ReaderT * e g) # | |

(Distributive f, Distributive g) => Distributive (Compose * * f g) # | |

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

The dual of `traverse`

`cotraverse`

f =`fmap`

f .`distribute`

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

The dual of `mapM`

`comapM`

f =`fmap`

f .`distributeM`

fmapCollect :: forall f a b. Distributive f => (a -> b) -> f a -> f b #

`fmapCollect`

is a viable default definition for `fmap`

given
a `Distributive`

instance defined in terms of `collect`

.