{-# Language DeriveDataTypeable, FlexibleContexts, FlexibleInstances, KindSignatures, MultiParamTypeClasses, RankNTypes,
StandaloneDeriving, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Transformation.Shallow (Functor(..), Foldable(..), Traversable(..), fmap) where
import Control.Applicative (Applicative, liftA2, pure)
import qualified Data.Functor as Rank1 (Functor, (<$>))
import qualified Data.Foldable as Rank1 (Foldable, foldMap)
import qualified Data.Traversable as Rank1 (Traversable, traverse)
import Data.Functor.Compose (Compose(Compose, getCompose))
import Data.Functor.Const (Const(Const, getConst))
import Data.Functor.Product (Product(Pair))
import Data.Functor.Sum (Sum(InL, InR))
import Data.Kind (Type)
import Data.Proxy (Proxy(Proxy))
import qualified Rank2
import Transformation (Transformation, Domain, Codomain, At)
import qualified Transformation
import Prelude hiding (Foldable(..), Traversable(..), Functor(..), Applicative(..), (<$>), fst, snd)
class (Transformation t, Rank2.Functor g) => Functor t g where
(<$>) :: t -> g (Domain t) -> g (Codomain t)
infixl 4 <$>
class (Transformation t, Rank2.Foldable g) => Foldable t g where
foldMap :: (Codomain t ~ Const m, Monoid m) => t -> g (Domain t) -> m
class (Transformation t, Rank2.Traversable g) => Traversable t g where
traverse :: Codomain t ~ Compose m f => t -> g (Domain t) -> m (g f)
newtype FunctorCompose (p :: Type -> Type) t = FunctorCompose t
newtype FoldableCompose (p :: Type -> Type) t = FoldableCompose t
newtype TraversableCompose (p :: Type -> Type) t = TraversableCompose t
instance Transformation t => Transformation (FunctorCompose p t) where
type Domain (FunctorCompose p t) = Compose p (Domain t)
type Codomain (FunctorCompose p t) = Compose p (Codomain t)
instance Transformation t => Transformation (FoldableCompose p t) where
type Domain (FoldableCompose p t) = Compose p (Domain t)
type Codomain (FoldableCompose p t) = Codomain t
instance (Transformation t, Codomain t ~ Compose q r) => Transformation (TraversableCompose p t) where
type Domain (TraversableCompose p t) = Compose p (Domain t)
type Codomain (TraversableCompose p t) = Compose (Outer (Codomain t)) (Compose p (Inner (Codomain t)))
type family Outer f where
Outer (Compose p q) = p
type family Inner f where
Inner (Compose p q) = q
instance (Rank1.Functor p, t `At` a) => FunctorCompose p t `At` a where
FunctorCompose t
t $ :: FunctorCompose p t
-> Domain (FunctorCompose p t) a -> Codomain (FunctorCompose p t) a
$ Compose p (Domain t a)
x = p (Codomain t a) -> Compose p (Codomain t) a
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose ((t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$) (Domain t a -> Codomain t a) -> p (Domain t a) -> p (Codomain t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> p (Domain t a)
x)
instance (Rank1.Foldable p, Codomain t ~ Const m, Monoid m, t `At` a) => FoldableCompose p t `At` a where
FoldableCompose t
t $ :: FoldableCompose p t
-> Domain (FoldableCompose p t) a
-> Codomain (FoldableCompose p t) a
$ Compose p (Domain t a)
x = m -> Const m a
forall {k} a (b :: k). a -> Const a b
Const (m -> Const m a) -> m -> Const m a
forall a b. (a -> b) -> a -> b
$ (Domain t a -> m) -> p (Domain t a) -> m
forall m a. Monoid m => (a -> m) -> p a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Rank1.foldMap (Const m a -> m
forall {k} a (b :: k). Const a b -> a
getConst (Const m a -> m) -> (Domain t a -> Const m a) -> Domain t a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$)) p (Domain t a)
x
instance (Rank1.Traversable p, Applicative q, Codomain t ~ Compose q r, t `At` a) => TraversableCompose p t `At` a where
TraversableCompose t
t $ :: TraversableCompose p t
-> Domain (TraversableCompose p t) a
-> Codomain (TraversableCompose p t) a
$ Compose p (Domain t a)
x = q (Compose p r a) -> Compose q (Compose p r) a
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (q (Compose p r a) -> Compose q (Compose p r) a)
-> q (Compose p r a) -> Compose q (Compose p r) a
forall a b. (a -> b) -> a -> b
$ p (r a) -> Compose p r a
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (p (r a) -> Compose p r a) -> q (p (r a)) -> q (Compose p r a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> (Domain t a -> q (r a)) -> p (Domain t a) -> q (p (r a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> p a -> f (p b)
Rank1.traverse (Compose q r a -> q (r a)
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Compose q r a -> q (r a))
-> (Domain t a -> Compose q r a) -> Domain t a -> q (r a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$)) p (Domain t a)
x
instance Transformation t => Functor t Rank2.Empty where
t
_ <$> :: t -> Empty (Domain t) -> Empty (Codomain t)
<$> Empty (Domain t)
Rank2.Empty = Empty (Codomain t)
forall {k} (f :: k). Empty f
Rank2.Empty
instance Transformation t => Functor t Proxy where
t
_ <$> :: t -> Proxy (Domain t) -> Proxy (Codomain t)
<$> Proxy (Domain t)
_ = Proxy (Codomain t)
forall {k} (t :: k). Proxy t
Proxy
instance Transformation t => Functor t (Const a) where
t
_ <$> :: t -> Const a (Domain t) -> Const a (Codomain t)
<$> Const a
a = a -> Const a (Codomain t)
forall {k} a (b :: k). a -> Const a b
Const a
a
instance (Transformation t, t `At` a) => Functor t (Rank2.Only a) where
t
t <$> :: t -> Only a (Domain t) -> Only a (Codomain t)
<$> Rank2.Only Domain t a
x = Codomain t a -> Only a (Codomain t)
forall {k} (a :: k) (f :: k -> *). f a -> Only a f
Rank2.Only (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$ Domain t a
x)
instance Functor t g => Functor t (Rank2.Identity g) where
t
f <$> :: t -> Identity g (Domain t) -> Identity g (Codomain t)
<$> Rank2.Identity g (Domain t)
g = g (Codomain t) -> Identity g (Codomain t)
forall {k} (g :: k -> *) (f :: k). g f -> Identity g f
Rank2.Identity (t
f t -> g (Domain t) -> g (Codomain t)
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> g (Domain t)
g)
instance (Transformation t, Functor (FunctorCompose p t) g, Rank1.Functor p) => Functor t (Rank2.Compose g p) where
t
t <$> :: t -> Compose g p (Domain t) -> Compose g p (Codomain t)
<$> Rank2.Compose g (Compose p (Domain t))
g = g (Compose p (Codomain t)) -> Compose g p (Codomain t)
forall {k1} {k} (g :: (k1 -> *) -> *) (p :: k -> *) (q :: k1 -> k).
g (Compose p q) -> Compose g p q
Rank2.Compose (t -> FunctorCompose p t
forall (p :: * -> *) t. t -> FunctorCompose p t
FunctorCompose t
t FunctorCompose p t
-> g (Domain (FunctorCompose p t))
-> g (Codomain (FunctorCompose p t))
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> g (Compose p (Domain t))
g (Domain (FunctorCompose p t))
g)
instance (Transformation t, t `At` a, Rank1.Functor g) => Functor t (Rank2.Flip g a) where
t
t <$> :: t -> Flip g a (Domain t) -> Flip g a (Codomain t)
<$> Rank2.Flip g (Domain t a)
g = g (Codomain t a) -> Flip g a (Codomain t)
forall {k} {k1} (g :: k -> *) (a :: k1) (f :: k1 -> k).
g (f a) -> Flip g a f
Rank2.Flip ((t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$) (Domain t a -> Codomain t a) -> g (Domain t a) -> g (Codomain t a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> g (Domain t a)
g)
instance (Functor t g, Functor t h) => Functor t (Product g h) where
t
t <$> :: t -> Product g h (Domain t) -> Product g h (Codomain t)
<$> Pair g (Domain t)
left h (Domain t)
right = g (Codomain t) -> h (Codomain t) -> Product g h (Codomain t)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (t
t t -> g (Domain t) -> g (Codomain t)
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> g (Domain t)
left) (t
t t -> h (Domain t) -> h (Codomain t)
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> h (Domain t)
right)
instance (Functor t g, Functor t h) => Functor t (Sum g h) where
t
t <$> :: t -> Sum g h (Domain t) -> Sum g h (Codomain t)
<$> InL g (Domain t)
g = g (Codomain t) -> Sum g h (Codomain t)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (t
t t -> g (Domain t) -> g (Codomain t)
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> g (Domain t)
g)
t
t <$> InR h (Domain t)
h = h (Codomain t) -> Sum g h (Codomain t)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (t
t t -> h (Domain t) -> h (Codomain t)
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
<$> h (Domain t)
h)
instance Transformation t => Foldable t Rank2.Empty where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Empty (Domain t) -> m
foldMap t
_ Empty (Domain t)
_ = m
forall a. Monoid a => a
mempty
instance Transformation t => Foldable t Proxy where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Proxy (Domain t) -> m
foldMap t
_ Proxy (Domain t)
_ = m
forall a. Monoid a => a
mempty
instance Transformation t => Foldable t (Const x) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Const x (Domain t) -> m
foldMap t
_ Const x (Domain t)
_ = m
forall a. Monoid a => a
mempty
instance (Transformation t, t `At` a, Codomain t ~ Const m) => Foldable t (Rank2.Only a) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Only a (Domain t) -> m
foldMap t
t (Rank2.Only Domain t a
x) = Const m a -> m
forall {k} a (b :: k). Const a b -> a
getConst (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$ Domain t a
x)
instance Foldable t g => Foldable t (Rank2.Identity g) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Identity g (Domain t) -> m
foldMap t
t (Rank2.Identity g (Domain t)
g) = t -> g (Domain t) -> m
forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t g (Domain t)
g
instance (Transformation t, Foldable (FoldableCompose p t) g, Rank1.Foldable p) => Foldable t (Rank2.Compose g p) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Compose g p (Domain t) -> m
foldMap t
t (Rank2.Compose g (Compose p (Domain t))
g) = FoldableCompose p t -> g (Domain (FoldableCompose p t)) -> m
forall m.
(Codomain (FoldableCompose p t) ~ Const m, Monoid m) =>
FoldableCompose p t -> g (Domain (FoldableCompose p t)) -> m
forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap (t -> FoldableCompose p t
forall (p :: * -> *) t. t -> FoldableCompose p t
FoldableCompose t
t) g (Compose p (Domain t))
g (Domain (FoldableCompose p t))
g
instance (Transformation t, t `At` a, Codomain t ~ Const m, Rank1.Foldable g) => Foldable t (Rank2.Flip g a) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Flip g a (Domain t) -> m
foldMap t
t (Rank2.Flip g (Domain t a)
g) = (Domain t a -> m) -> g (Domain t a) -> m
forall m a. Monoid m => (a -> m) -> g a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Rank1.foldMap (Const m a -> m
forall {k} a (b :: k). Const a b -> a
getConst (Const m a -> m) -> (Domain t a -> Const m a) -> Domain t a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$)) g (Domain t a)
g
instance (Foldable t g, Foldable t h, Codomain t ~ Const m, Monoid m) => Foldable t (Product g h) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Product g h (Domain t) -> m
foldMap t
t (Pair g (Domain t)
left h (Domain t)
right) = t -> g (Domain t) -> m
forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t g (Domain t)
left m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` t -> h (Domain t) -> m
forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> h (Domain t) -> m
forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t h (Domain t)
right
instance (Foldable t g, Foldable t h) => Foldable t (Sum g h) where
foldMap :: forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> Sum g h (Domain t) -> m
foldMap t
t (InL g (Domain t)
g) = t -> g (Domain t) -> m
forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t g (Domain t)
g
foldMap t
t (InR h (Domain t)
h) = t -> h (Domain t) -> m
forall m.
(Codomain t ~ Const m, Monoid m) =>
t -> h (Domain t) -> m
forall t (g :: (* -> *) -> *) m.
(Foldable t g, Codomain t ~ Const m, Monoid m) =>
t -> g (Domain t) -> m
foldMap t
t h (Domain t)
h
instance (Transformation t, Codomain t ~ Compose m f, Applicative m) => Traversable t Rank2.Empty where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Empty (Domain t) -> m (Empty f)
traverse t
_ Empty (Domain t)
_ = Empty f -> m (Empty f)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Empty f
forall {k} (f :: k). Empty f
Rank2.Empty
instance (Transformation t, Codomain t ~ Compose m f, Applicative m) => Traversable t Proxy where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Proxy (Domain t) -> m (Proxy f)
traverse t
_ Proxy (Domain t)
_ = Proxy f -> m (Proxy f)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Proxy f
forall {k} (t :: k). Proxy t
Proxy
instance (Transformation t, Codomain t ~ Compose m f, Applicative m) => Traversable t (Const x) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Const x (Domain t) -> m (Const x f)
traverse t
_ (Const x
x) = Const x f -> m (Const x f)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (x -> Const x f
forall {k} a (b :: k). a -> Const a b
Const x
x)
instance (Transformation t, t `At` a, Codomain t ~ Compose m f, Rank1.Functor m) => Traversable t (Rank2.Only a) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Only a (Domain t) -> m (Only a f)
traverse t
t (Rank2.Only Domain t a
x) = f a -> Only a f
forall {k} (a :: k) (f :: k -> *). f a -> Only a f
Rank2.Only (f a -> Only a f) -> m (f a) -> m (Only a f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> Compose m f a -> m (f a)
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$ Domain t a
x)
instance (Traversable t g, Codomain t ~ Compose m f, Rank1.Functor m) => Traversable t (Rank2.Identity g) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Identity g (Domain t) -> m (Identity g f)
traverse t
t (Rank2.Identity g (Domain t)
g) = g f -> Identity g f
forall {k} (g :: k -> *) (f :: k). g f -> Identity g f
Rank2.Identity (g f -> Identity g f) -> m (g f) -> m (Identity g f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> t -> g (Domain t) -> m (g f)
forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
traverse t
t g (Domain t)
g
instance (Transformation t, Traversable (TraversableCompose p t) g,
Rank1.Traversable p, Codomain t ~ Compose q r, Rank1.Functor q) => Traversable t (Rank2.Compose g p) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Compose g p (Domain t) -> m (Compose g p f)
traverse t
t (Rank2.Compose g (Compose p (Domain t))
g) = g (Compose p f) -> Compose g p f
forall {k1} {k} (g :: (k1 -> *) -> *) (p :: k -> *) (q :: k1 -> k).
g (Compose p q) -> Compose g p q
Rank2.Compose (g (Compose p f) -> Compose g p f)
-> m (g (Compose p f)) -> m (Compose g p f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> TraversableCompose p t
-> g (Domain (TraversableCompose p t)) -> m (g (Compose p f))
forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
forall (m :: * -> *) (f :: * -> *).
(Codomain (TraversableCompose p t) ~ Compose m f) =>
TraversableCompose p t
-> g (Domain (TraversableCompose p t)) -> m (g f)
traverse (t -> TraversableCompose p t
forall (p :: * -> *) t. t -> TraversableCompose p t
TraversableCompose t
t) g (Compose p (Domain t))
g (Domain (TraversableCompose p t))
g
instance (Transformation t, t `At` a,
Codomain t ~ Compose m f, Applicative m, Rank1.Traversable g) => Traversable t (Rank2.Flip g a) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Flip g a (Domain t) -> m (Flip g a f)
traverse t
t (Rank2.Flip g (Domain t a)
g) = g (f a) -> Flip g a f
forall {k} {k1} (g :: k -> *) (a :: k1) (f :: k1 -> k).
g (f a) -> Flip g a f
Rank2.Flip (g (f a) -> Flip g a f) -> m (g (f a)) -> m (Flip g a f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> (Domain t a -> m (f a)) -> g (Domain t a) -> m (g (f a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> g a -> f (g b)
Rank1.traverse (Compose m f a -> m (f a)
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Compose m f a -> m (f a))
-> (Domain t a -> Compose m f a) -> Domain t a -> m (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t
t t -> Domain t a -> Codomain t a
forall t x. At t x => t -> Domain t x -> Codomain t x
Transformation.$)) g (Domain t a)
g
instance (Traversable t g, Traversable t h, Codomain t ~ Compose m f, Applicative m) => Traversable t (Product g h) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Product g h (Domain t) -> m (Product g h f)
traverse t
t (Pair g (Domain t)
left h (Domain t)
right) = (g f -> h f -> Product g h f)
-> m (g f) -> m (h f) -> m (Product g h f)
forall a b c. (a -> b -> c) -> m a -> m b -> m c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 g f -> h f -> Product g h f
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (t -> g (Domain t) -> m (g f)
forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
traverse t
t g (Domain t)
left) (t -> h (Domain t) -> m (h f)
forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> h (Domain t) -> m (h f)
traverse t
t h (Domain t)
right)
instance (Traversable t g, Traversable t h, Codomain t ~ Compose m f, Rank1.Functor m) => Traversable t (Sum g h) where
traverse :: forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> Sum g h (Domain t) -> m (Sum g h f)
traverse t
t (InL g (Domain t)
g) = g f -> Sum g h f
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (g f -> Sum g h f) -> m (g f) -> m (Sum g h f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> t -> g (Domain t) -> m (g f)
forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
traverse t
t g (Domain t)
g
traverse t
t (InR h (Domain t)
h) = h f -> Sum g h f
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (h f -> Sum g h f) -> m (h f) -> m (Sum g h f)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Rank1.<$> t -> h (Domain t) -> m (h f)
forall t (g :: (* -> *) -> *) (m :: * -> *) (f :: * -> *).
(Traversable t g, Codomain t ~ Compose m f) =>
t -> g (Domain t) -> m (g f)
forall (m :: * -> *) (f :: * -> *).
(Codomain t ~ Compose m f) =>
t -> h (Domain t) -> m (h f)
traverse t
t h (Domain t)
h
fmap :: Functor t g => t -> g (Domain t) -> g (Codomain t)
fmap :: forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
fmap = t -> g (Domain t) -> g (Codomain t)
forall t (g :: (* -> *) -> *).
Functor t g =>
t -> g (Domain t) -> g (Codomain t)
(<$>)