{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
#if __GLASGOW_HASKELL__ >= 706
{-# LANGUAGE PolyKinds #-}
#endif
module Data.Distributive
( Distributive(..)
, cotraverse
, comapM
) where
import Control.Applicative
import Control.Applicative.Backwards
import Control.Monad (liftM)
#if __GLASGOW_HASKELL__ < 707
import Control.Monad.Instances ()
#endif
import Control.Monad.Trans.Identity
import Control.Monad.Trans.Reader
import Data.Coerce
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Functor.Product
import Data.Functor.Reverse
import qualified Data.Monoid as Monoid
import Data.Orphans ()
#if MIN_VERSION_base(4,4,0)
import Data.Complex
#endif
#if __GLASGOW_HASKELL__ >= 707 || defined(MIN_VERSION_tagged)
import Data.Proxy
#endif
#if __GLASGOW_HASKELL__ >= 800 || defined(MIN_VERSION_semigroups)
import qualified Data.Semigroup as Semigroup
#endif
#ifdef MIN_VERSION_tagged
import Data.Tagged
#endif
#if __GLASGOW_HASKELL__ >= 702
import GHC.Generics (U1(..), (:*:)(..), (:.:)(..), Par1(..), Rec1(..), M1(..))
#endif
#ifdef HLINT
{-# ANN module "hlint: ignore Use section" #-}
#endif
class Functor g => Distributive g where
#if __GLASGOW_HASKELL__ >= 707
{-# MINIMAL distribute | collect #-}
#endif
distribute :: Functor f => f (g a) -> g (f a)
distribute = forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall a. a -> a
id
collect :: Functor f => (a -> g b) -> f a -> g (f b)
collect a -> g b
f = forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> g b
f
distributeM :: Monad m => m (g a) -> g (m a)
distributeM = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad
collectM :: Monad m => (a -> g b) -> m a -> g (m b)
collectM a -> g b
f = forall (g :: * -> *) (m :: * -> *) a.
(Distributive g, Monad m) =>
m (g a) -> g (m a)
distributeM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM a -> g b
f
cotraverse :: (Distributive g, Functor f) => (f a -> b) -> f (g a) -> g b
cotraverse :: forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(f a -> b) -> f (g a) -> g b
cotraverse f a -> b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap f a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute
comapM :: (Distributive g, Monad m) => (m a -> b) -> m (g a) -> g b
comapM :: forall (g :: * -> *) (m :: * -> *) a b.
(Distributive g, Monad m) =>
(m a -> b) -> m (g a) -> g b
comapM m a -> b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (m :: * -> *) a.
(Distributive g, Monad m) =>
m (g a) -> g (m a)
distributeM
instance Distributive Identity where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Identity b) -> f a -> Identity (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall a b f . Functor f => (a -> Identity b) -> f a -> Identity (f b)
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Identity a) -> Identity (f a)
distribute = forall a. a -> Identity a
Identity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Identity a -> a
runIdentity
#if __GLASGOW_HASKELL__ >= 707 || defined(MIN_VERSION_tagged)
instance Distributive Proxy where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Proxy b) -> f a -> Proxy (f b)
collect a -> Proxy b
_ f a
_ = forall {k} (t :: k). Proxy t
Proxy
distribute :: forall (f :: * -> *) a. Functor f => f (Proxy a) -> Proxy (f a)
distribute f (Proxy a)
_ = forall {k} (t :: k). Proxy t
Proxy
#endif
#if defined(MIN_VERSION_tagged)
instance Distributive (Tagged t) where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Tagged t b) -> f a -> Tagged t (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall a b f . Functor f => (a -> Tagged t b) -> f a -> Tagged t (f b)
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Tagged t a) -> Tagged t (f a)
distribute = forall {k} (s :: k) b. b -> Tagged s b
Tagged forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {k} (s :: k) b. Tagged s b -> b
unTagged
#endif
instance Distributive ((->)e) where
distribute :: forall (f :: * -> *) a. Functor f => f (e -> a) -> e -> f a
distribute f (e -> a)
a e
e = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. (a -> b) -> a -> b
$e
e) f (e -> a)
a
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> e -> b) -> f a -> e -> f b
collect a -> e -> b
f f a
q e
e = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> e -> b
f e
e) f a
q
instance Distributive g => Distributive (ReaderT e g) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (ReaderT e g a) -> ReaderT e g (f a)
distribute f (ReaderT e g a)
a = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ \e
e -> forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT e
e) f (ReaderT e g a)
a
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> ReaderT e g b) -> f a -> ReaderT e g (f b)
collect a -> ReaderT e g b
f f a
x = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ \e
e -> forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect (\a
a -> forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (a -> ReaderT e g b
f a
a) e
e) f a
x
instance Distributive g => Distributive (IdentityT g) where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> IdentityT g b) -> f a -> IdentityT g (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect :: (a -> g b) -> f a -> g (f b))
:: forall a b f . Functor f => (a -> IdentityT g b) -> f a -> IdentityT g (f b)
instance (Distributive f, Distributive g) => Distributive (Compose f g) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Compose f g a) -> Compose f g (f a)
distribute = forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Compose f g b) -> f a -> Compose f g (f b)
collect a -> Compose f g b
f = forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect (coerce :: forall a b. Coercible a b => a -> b
coerce a -> Compose f g b
f)
instance (Distributive f, Distributive g) => Distributive (Product f g) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Product f g a) -> Product f g (f a)
distribute f (Product f g a)
wp = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k} {f :: k -> *} {g :: k -> *} {a :: k}.
Product f g a -> f a
fstP f (Product f g a)
wp) (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k} {f :: k -> *} {g :: k -> *} {a :: k}.
Product f g a -> g a
sndP f (Product f g a)
wp) where
fstP :: Product f g a -> f a
fstP (Pair f a
a g a
_) = f a
a
sndP :: Product f g a -> g a
sndP (Pair f a
_ g a
b) = g a
b
instance Distributive f => Distributive (Backwards f) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Backwards f a) -> Backwards f (f a)
distribute = forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Backwards f b) -> f a -> Backwards f (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect :: (a -> f b) -> g a -> f (g b))
:: forall g a b . Functor g
=> (a -> Backwards f b) -> g a -> Backwards f (g b)
instance Distributive f => Distributive (Reverse f) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (Reverse f a) -> Reverse f (f a)
distribute = forall {k} (f :: k -> *) (a :: k). f a -> Reverse f a
Reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k} (f :: k -> *) (a :: k). Reverse f a -> f a
getReverse
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Reverse f b) -> f a -> Reverse f (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect :: (a -> f b) -> g a -> f (g b))
:: forall g a b . Functor g
=> (a -> Reverse f b) -> g a -> Reverse f (g b)
instance Distributive Monoid.Dual where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Dual b) -> f a -> Dual (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Monoid.Dual b) -> f a -> Monoid.Dual (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (Dual a) -> Dual (f a)
distribute = forall a. a -> Dual a
Monoid.Dual forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Dual a -> a
Monoid.getDual
instance Distributive Monoid.Product where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Product b) -> f a -> Product (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Monoid.Product b) -> f a -> Monoid.Product (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (Product a) -> Product (f a)
distribute = forall a. a -> Product a
Monoid.Product forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Product a -> a
Monoid.getProduct
instance Distributive Monoid.Sum where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Sum b) -> f a -> Sum (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Monoid.Sum b) -> f a -> Monoid.Sum (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (Sum a) -> Sum (f a)
distribute = forall a. a -> Sum a
Monoid.Sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Sum a -> a
Monoid.getSum
#if __GLASGOW_HASKELL__ >= 800 || defined(MIN_VERSION_semigroups)
instance Distributive Semigroup.Min where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Min b) -> f a -> Min (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Semigroup.Min b) -> f a -> Semigroup.Min (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (Min a) -> Min (f a)
distribute = forall a. a -> Min a
Semigroup.Min forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Min a -> a
Semigroup.getMin
instance Distributive Semigroup.Max where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Max b) -> f a -> Max (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Semigroup.Max b) -> f a -> Semigroup.Max (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (Max a) -> Max (f a)
distribute = forall a. a -> Max a
Semigroup.Max forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Max a -> a
Semigroup.getMax
instance Distributive Semigroup.First where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> First b) -> f a -> First (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Semigroup.First b) -> f a -> Semigroup.First (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (First a) -> First (f a)
distribute = forall a. a -> First a
Semigroup.First forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. First a -> a
Semigroup.getFirst
instance Distributive Semigroup.Last where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Last b) -> f a -> Last (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f
=> (a -> Semigroup.Last b) -> f a -> Semigroup.Last (f b)
distribute :: forall (f :: * -> *) a. Functor f => f (Last a) -> Last (f a)
distribute = forall a. a -> Last a
Semigroup.Last forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Last a -> a
Semigroup.getLast
#endif
#if MIN_VERSION_base(4,4,0)
instance Distributive Complex where
distribute :: forall (f :: * -> *) a. Functor f => f (Complex a) -> Complex (f a)
distribute f (Complex a)
wc = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a}. Complex a -> a
realP f (Complex a)
wc forall a. a -> a -> Complex a
:+ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a}. Complex a -> a
imagP f (Complex a)
wc where
realP :: Complex a -> a
realP (a
r :+ a
_) = a
r
imagP :: Complex a -> a
imagP (a
_ :+ a
i) = a
i
#endif
instance (Distributive m, Monad m) => Distributive (WrappedMonad m) where
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> WrappedMonad m b) -> f a -> WrappedMonad m (f b)
collect a -> WrappedMonad m b
f = forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect (coerce :: forall a b. Coercible a b => a -> b
coerce a -> WrappedMonad m b
f)
#if __GLASGOW_HASKELL__ >= 702
instance Distributive U1 where
distribute :: forall (f :: * -> *) a. Functor f => f (U1 a) -> U1 (f a)
distribute f (U1 a)
_ = forall k (p :: k). U1 p
U1
instance (Distributive a, Distributive b) => Distributive (a :*: b) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f ((:*:) a b a) -> (:*:) a b (f a)
distribute f ((:*:) a b a)
f = forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k} {f :: k -> *} {g :: k -> *} {p :: k}. (:*:) f g p -> f p
fstP f ((:*:) a b a)
f forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall {k} {f :: k -> *} {g :: k -> *} {p :: k}. (:*:) f g p -> g p
sndP f ((:*:) a b a)
f where
fstP :: (:*:) f g p -> f p
fstP (f p
l :*: g p
_) = f p
l
sndP :: (:*:) f g p -> g p
sndP (f p
_ :*: g p
r) = g p
r
instance (Distributive a, Distributive b) => Distributive (a :.: b) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f ((:.:) a b a) -> (:.:) a b (f a)
distribute = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
(:.:) f g p -> f (g p)
unComp1
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> (:.:) a b b) -> f a -> (:.:) a b (f b)
collect a -> (:.:) a b b
f = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect (coerce :: forall a b. Coercible a b => a -> b
coerce a -> (:.:) a b b
f)
instance Distributive Par1 where
distribute :: forall (f :: * -> *) a. Functor f => f (Par1 a) -> Par1 (f a)
distribute = forall p. p -> Par1 p
Par1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall p. Par1 p -> p
unPar1
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Par1 b) -> f a -> Par1 (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap :: (a -> b) -> f a -> f b)
:: forall f a b . Functor f => (a -> Par1 b) -> f a -> Par1 (f b)
instance Distributive f => Distributive (Rec1 f) where
distribute :: forall (f :: * -> *) a. Functor f => f (Rec1 f a) -> Rec1 f (f a)
distribute = forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall k (f :: k -> *) (p :: k). Rec1 f p -> f p
unRec1
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> Rec1 f b) -> f a -> Rec1 f (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect :: (a -> f b) -> g a -> f (g b))
:: forall g a b . Functor g
=> (a -> Rec1 f b) -> g a -> Rec1 f (g b)
instance Distributive f => Distributive (M1 i c f) where
distribute :: forall (f :: * -> *) a.
Functor f =>
f (M1 i c f a) -> M1 i c f (f a)
distribute = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1
collect :: forall (f :: * -> *) a b.
Functor f =>
(a -> M1 i c f b) -> f a -> M1 i c f (f b)
collect = coerce :: forall a b. Coercible a b => a -> b
coerce (forall (g :: * -> *) (f :: * -> *) a b.
(Distributive g, Functor f) =>
(a -> g b) -> f a -> g (f b)
collect :: (a -> f b) -> g a -> f (g b))
:: forall g a b . Functor g
=> (a -> M1 i c f b) -> g a -> M1 i c f (g b)
#endif