Data.Distributive.Generic

distributive-0.6.2.1: Distributive functors -- Dual to Traversable

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 | Haskell2010

Data.Distributive.Generic

Description

Synopsis

- class GDistributive (g :: Type -> Type) where
  - gcollect :: Functor f => (a -> g b) -> f a -> g (f b)
- genericCollect :: (Functor f, Generic1 g, GDistributive (Rep1 g)) => (a -> g b) -> f a -> g (f b)
- genericDistribute :: (Functor f, Generic1 g, GDistributive (Rep1 g)) => f (g a) -> g (f a)

# Documentation

class GDistributive (g :: Type -> Type) where #

Methods

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

#### Instances

Instances details

GDistributive Par1 # |
Instance details Defined in Data.Distributive.Generic Methods gcollect :: Functor f => (a -> Par1 b) -> f a -> Par1 (f b) #
GDistributive (U1 :: Type -> Type) # |
Instance details Defined in Data.Distributive.Generic Methods gcollect :: Functor f => (a -> U1 b) -> f a -> U1 (f b) #
Distributive f => GDistributive (Rec1 f) # |
Instance details Defined in Data.Distributive.Generic Methods gcollect :: Functor f0 => (a -> Rec1 f b) -> f0 a -> Rec1 f (f0 b) #
(GDistributive a, GDistributive b) => GDistributive (a :*: b) # |
Instance details Defined in Data.Distributive.Generic Methods gcollect :: Functor f => (a0 -> (a :*: b) b0) -> f a0 -> (a :*: b) (f b0) #
(Distributive a, GDistributive b) => GDistributive (a :.: b) # |
Instance details Defined in Data.Distributive.Generic Methods gcollect :: Functor f => (a0 -> (a :.: b) b0) -> f a0 -> (a :.: b) (f b0) #
GDistributive f => GDistributive (M1 i c f) # |
Instance details Defined in Data.Distributive.Generic Methods gcollect :: Functor f0 => (a -> M1 i c f b) -> f0 a -> M1 i c f (f0 b) #

genericCollect :: (Functor f, Generic1 g, GDistributive (Rep1 g)) => (a -> g b) -> f a -> g (f b) #

`collect` derived from a `Generic1` type

This can be used to easily produce a `Distributive` instance for a type with a `Generic1` instance,

    data V2 a = V2 a a deriving (Show, Functor, Generic1)
    instance Distributive V2' where collect = genericCollect

genericDistribute :: (Functor f, Generic1 g, GDistributive (Rep1 g)) => f (g a) -> g (f a) #

`distribute` derived from a `Generic1` type

It's often more efficient to use `genericCollect` instead.