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 | Safe |
Language | Haskell98 |
- class Functor g => Distributive g where
- cotraverse :: (Functor f, Distributive g) => (f a -> b) -> f (g a) -> g b
- comapM :: (Monad m, Distributive g) => (m a -> b) -> m (g a) -> g b
Documentation
class Functor g => Distributive g where Source
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.
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
collect :: Functor f => (a -> g b) -> f a -> g (f b) Source
collect
f =distribute
.fmap
f
distributeM :: Monad m => m (g a) -> g (m a) Source
The dual of sequence
distributeM
=fmap
unwrapMonad
.distribute
.WrapMonad
collectM :: Monad m => (a -> g b) -> m a -> g (m b) Source
collectM
=distributeM
.liftM
f
Distributive Identity Source | |
Distributive Complex Source | |
Distributive Dual Source | |
Distributive Sum Source | |
Distributive Product Source | |
Distributive ((->) e) Source | |
Distributive (Proxy (TYPE Lifted)) Source | |
Distributive f => Distributive (Reverse (TYPE Lifted) f) Source | |
Distributive f => Distributive (Backwards (TYPE Lifted) f) Source | |
Distributive g => Distributive (IdentityT (TYPE Lifted) g) Source | |
Distributive (Tagged (TYPE Lifted) t) Source | |
(Distributive f, Distributive g) => Distributive (Product (TYPE Lifted) f g) Source | |
Distributive g => Distributive (ReaderT (TYPE Lifted) e g) Source | |
(Distributive f, Distributive g) => Distributive (Compose (TYPE Lifted) (TYPE Lifted) f g) Source | |
cotraverse :: (Functor f, Distributive g) => (f a -> b) -> f (g a) -> g b Source
The dual of traverse
cotraverse
f =fmap
f .distribute
comapM :: (Monad m, Distributive g) => (m a -> b) -> m (g a) -> g b Source
The dual of mapM
comapM
f =fmap
f .distributeM