-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | standard type constructor class hierarchy, only with methods of rank 2 types
--   
--   A mirror image of the standard type constructor class hierarchy rooted
--   in <a>Functor</a>, except with methods of rank 2 types and class
--   instances of kind <tt>(k-&gt;*)-&gt;*</tt>. The classes enable generic
--   handling of heterogenously typed data structures and other neat
--   tricks.
@package rank2classes
@version 1.3.1.1


-- | Import this module qualified, like this:
--   
--   <pre>
--   import qualified Rank2
--   </pre>
--   
--   This will bring into scope the standard classes <a>Functor</a>,
--   <a>Applicative</a>, <a>Foldable</a>, and <a>Traversable</a>, but with
--   a <tt>Rank2.</tt> prefix and a twist that their methods operate on a
--   heterogenous collection. The same property is shared by the two less
--   standard classes <a>Apply</a> and <a>Distributive</a>.
module Rank2

-- | Equivalent of <a>Functor</a> for rank 2 data types, satisfying the
--   usual functor laws
--   
--   <pre>
--   id &lt;$&gt; g == g
--   (p . q) &lt;$&gt; g == p &lt;$&gt; (q &lt;$&gt; g)
--   </pre>
class Functor g
(<$>) :: Functor g => (forall a. p a -> q a) -> g p -> g q

-- | Subclass of <a>Functor</a> halfway to <a>Applicative</a>, satisfying
--   
--   <pre>
--   (.) &lt;$&gt; u &lt;*&gt; v &lt;*&gt; w == u &lt;*&gt; (v &lt;*&gt; w)
--   </pre>
class Functor g => Apply g

-- | Equivalent of <a>&lt;*&gt;</a> for rank 2 data types
(<*>) :: Apply g => g (p ~> q) -> g p -> g q

-- | Equivalent of <a>liftA2</a> for rank 2 data types
liftA2 :: Apply g => (forall a. p a -> q a -> r a) -> g p -> g q -> g r

-- | Equivalent of <a>liftA3</a> for rank 2 data types
liftA3 :: Apply g => (forall a. p a -> q a -> r a -> s a) -> g p -> g q -> g r -> g s

-- | Equivalent of <a>Applicative</a> for rank 2 data types
class Apply g => Applicative g
pure :: Applicative g => (forall a. f a) -> g f

-- | Equivalent of <a>Foldable</a> for rank 2 data types
class Foldable g
foldMap :: (Foldable g, Monoid m) => (forall a. p a -> m) -> g p -> m

-- | Equivalent of <a>Traversable</a> for rank 2 data types
class (Functor g, Foldable g) => Traversable g
traverse :: (Traversable g, Applicative m) => (forall a. p a -> m (q a)) -> g p -> m (g q)
sequence :: (Traversable g, Applicative m) => g (Compose m p) -> m (g p)

-- | Equivalent of <a>Distributive</a> for rank 2 data types
class DistributiveTraversable g => Distributive g
collect :: (Distributive g, Functor f1) => (a -> g f2) -> f1 a -> g (Compose f1 f2)
distribute :: (Distributive g, Functor f1) => f1 (g f2) -> g (Compose f1 f2)

-- | Dual of <a>traverse</a>, equivalent of <a>cotraverse</a> for rank 2
--   data types
cotraverse :: (Distributive g, Functor m) => (forall a. m (p a) -> q a) -> m (g p) -> g q

-- | A weaker <a>Distributive</a> that requires <a>Traversable</a> to use,
--   not just a <a>Functor</a>.
class Functor g => DistributiveTraversable (g :: (k -> *) -> *)
collectTraversable :: (DistributiveTraversable g, Traversable f1) => (a -> g f2) -> f1 a -> g (Compose f1 f2)
distributeTraversable :: (DistributiveTraversable g, Traversable f1) => f1 (g f2) -> g (Compose f1 f2)
cotraverseTraversable :: (DistributiveTraversable g, Traversable f1) => (forall x. f1 (f2 x) -> f x) -> f1 (g f2) -> g f
cotraverseTraversable :: (DistributiveTraversable g, Traversable m, Distributive g) => (forall a. m (p a) -> q a) -> m (g p) -> g q

-- | A variant of <a>distribute</a> convenient with <a>Monad</a> instances
distributeJoin :: (Distributive g, Monad f) => f (g f) -> g f

-- | Right-to-left composition of functors. The composition of applicative
--   functors is always applicative, but the composition of monads is not
--   always a monad.
newtype Compose (f :: k -> Type) (g :: k1 -> k) (a :: k1) :: forall k k1. () => k -> Type -> k1 -> k -> k1 -> Type
Compose :: f (g a) -> Compose
[getCompose] :: Compose -> f (g a)
infixr 9 `Compose`
infixr 9 `Compose`

-- | A rank-2 equivalent of '()', a zero-element tuple
data Empty f
Empty :: Empty f

-- | A rank-2 tuple of only one element
newtype Only a f
Only :: f a -> Only a f
[fromOnly] :: Only a f -> f a

-- | A nested parametric type represented as a rank-2 type
newtype Flip g a f
Flip :: g (f a) -> Flip g a f
[unFlip] :: Flip g a f -> g (f a)

-- | Equivalent of <a>Identity</a> for rank 2 data types
newtype Identity g f
Identity :: g f -> Identity g f
[runIdentity] :: Identity g f -> g f

-- | Lifted product of functors.
data Product (f :: k -> Type) (g :: k -> Type) (a :: k) :: forall k. () => k -> Type -> k -> Type -> k -> Type
Pair :: f a -> g a -> Product

-- | Lifted sum of functors.
data Sum (f :: k -> Type) (g :: k -> Type) (a :: k) :: forall k. () => k -> Type -> k -> Type -> k -> Type
InL :: f a -> Sum
InR :: g a -> Sum

-- | Wrapper for functions that map the argument constructor type
newtype Arrow p q a
Arrow :: (p a -> q a) -> Arrow p q a
[apply] :: Arrow p q a -> p a -> q a
type (~>) = Arrow
infixr 0 ~>

-- | Helper function for accessing the first field of a <a>Pair</a>
fst :: Product g h p -> g p

-- | Helper function for accessing the second field of a <a>Pair</a>
snd :: Product g h p -> h p

-- | Alphabetical synonym for <a>&lt;*&gt;</a>
ap :: Apply g => g (p ~> q) -> g p -> g q

-- | Alphabetical synonym for <a>&lt;$&gt;</a>
fmap :: Functor g => (forall a. p a -> q a) -> g p -> g q
liftA4 :: Apply g => (forall a. p a -> q a -> r a -> s a -> t a) -> g p -> g q -> g r -> g s -> g t
liftA5 :: Apply g => (forall a. p a -> q a -> r a -> s a -> t a -> u a) -> g p -> g q -> g r -> g s -> g t -> g u

-- | Like <a>fmap</a>, but traverses over its argument
fmapTraverse :: (DistributiveTraversable f, Traversable g) => (forall a. g (t a) -> u a) -> g (f t) -> f u

-- | Like <a>liftA2</a>, but traverses over its first argument
liftA2Traverse1 :: (Apply f, DistributiveTraversable f, Traversable g) => (forall a. g (t a) -> u a -> v a) -> g (f t) -> f u -> f v

-- | Like <a>liftA2</a>, but traverses over its second argument
liftA2Traverse2 :: (Apply f, DistributiveTraversable f, Traversable g) => (forall a. t a -> g (u a) -> v a) -> f t -> g (f u) -> f v

-- | Like <a>liftA2</a>, but traverses over both its arguments
liftA2TraverseBoth :: (Apply f, DistributiveTraversable f, Traversable g1, Traversable g2) => (forall a. g1 (t a) -> g2 (u a) -> v a) -> g1 (f t) -> g2 (f u) -> f v

-- | Synonym for <a>cotraverse</a>

-- | <i>Deprecated: Use cotraverse instead.</i>
distributeWith :: (Distributive g, Functor f) => (forall i. f (a i) -> b i) -> f (g a) -> g b

-- | Synonym for <a>cotraverseTraversable</a>

-- | <i>Deprecated: Use cotraverseTraversable instead.</i>
distributeWithTraversable :: (DistributiveTraversable g, Traversable m) => (forall a. m (p a) -> q a) -> m (g p) -> g q
instance forall k1 (g :: k1 -> *) k2 (a :: k2) (f :: k2 -> k1). GHC.Show.Show (g (f a)) => GHC.Show.Show (Rank2.Flip g a f)
instance forall k1 (g :: k1 -> *) k2 (a :: k2) (f :: k2 -> k1). GHC.Classes.Ord (g (f a)) => GHC.Classes.Ord (Rank2.Flip g a f)
instance forall k1 (g :: k1 -> *) k2 (a :: k2) (f :: k2 -> k1). GHC.Classes.Eq (g (f a)) => GHC.Classes.Eq (Rank2.Flip g a f)
instance forall k (g :: k -> *) (f :: k). GHC.Show.Show (g f) => GHC.Show.Show (Rank2.Identity g f)
instance forall k (g :: k -> *) (f :: k). GHC.Classes.Ord (g f) => GHC.Classes.Ord (Rank2.Identity g f)
instance forall k (g :: k -> *) (f :: k). GHC.Classes.Eq (g f) => GHC.Classes.Eq (Rank2.Identity g f)
instance forall k (a :: k) (f :: k -> *). GHC.Show.Show (f a) => GHC.Show.Show (Rank2.Only a f)
instance forall k (a :: k) (f :: k -> *). GHC.Classes.Ord (f a) => GHC.Classes.Ord (Rank2.Only a f)
instance forall k (a :: k) (f :: k -> *). GHC.Classes.Eq (f a) => GHC.Classes.Eq (Rank2.Only a f)
instance forall k (f :: k). GHC.Show.Show (Rank2.Empty f)
instance forall k (f :: k). GHC.Classes.Ord (Rank2.Empty f)
instance forall k (f :: k). GHC.Classes.Eq (Rank2.Empty f)
instance forall k1 k2 (g :: k2 -> *) (f :: k1 -> k2) (a :: k1). GHC.Base.Semigroup (g (f a)) => GHC.Base.Semigroup (Rank2.Flip g a f)
instance forall k1 k2 (g :: k2 -> *) (f :: k1 -> k2) (a :: k1). GHC.Base.Monoid (g (f a)) => GHC.Base.Monoid (Rank2.Flip g a f)
instance forall k (g :: * -> *) (a :: k). GHC.Base.Functor g => Rank2.Functor (Rank2.Flip g a)
instance forall k (g :: * -> *) (a :: k). GHC.Base.Applicative g => Rank2.Apply (Rank2.Flip g a)
instance forall k (g :: * -> *) (a :: k). GHC.Base.Applicative g => Rank2.Applicative (Rank2.Flip g a)
instance forall k (g :: * -> *) (a :: k). Data.Foldable.Foldable g => Rank2.Foldable (Rank2.Flip g a)
instance forall k (g :: * -> *) (a :: k). Data.Traversable.Traversable g => Rank2.Traversable (Rank2.Flip g a)
instance forall k (g :: (k -> *) -> *). Rank2.Functor g => Rank2.Functor (Rank2.Identity g)
instance forall k (g :: (k -> *) -> *). Rank2.Foldable g => Rank2.Foldable (Rank2.Identity g)
instance forall k (g :: (k -> *) -> *). Rank2.Traversable g => Rank2.Traversable (Rank2.Identity g)
instance forall k (g :: (k -> *) -> *). Rank2.Apply g => Rank2.Apply (Rank2.Identity g)
instance forall k (g :: (k -> *) -> *). Rank2.Applicative g => Rank2.Applicative (Rank2.Identity g)
instance forall k (g :: (k -> *) -> *). Rank2.DistributiveTraversable g => Rank2.DistributiveTraversable (Rank2.Identity g)
instance forall k (g :: (k -> *) -> *). Rank2.Distributive g => Rank2.Distributive (Rank2.Identity g)
instance forall k (a :: k). Rank2.Functor (Rank2.Only a)
instance forall k (x :: k). Rank2.Foldable (Rank2.Only x)
instance forall k (x :: k). Rank2.Traversable (Rank2.Only x)
instance forall k (x :: k). Rank2.Apply (Rank2.Only x)
instance forall k (x :: k). Rank2.Applicative (Rank2.Only x)
instance forall k (x :: k). Rank2.DistributiveTraversable (Rank2.Only x)
instance forall k (x :: k). Rank2.Distributive (Rank2.Only x)
instance Rank2.Functor Rank2.Empty
instance Rank2.Foldable Rank2.Empty
instance Rank2.Traversable Rank2.Empty
instance Rank2.Apply Rank2.Empty
instance Rank2.Applicative Rank2.Empty
instance Rank2.DistributiveTraversable Rank2.Empty
instance Rank2.Distributive Rank2.Empty
instance Rank2.DistributiveTraversable Data.Proxy.Proxy
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.DistributiveTraversable g, Rank2.DistributiveTraversable h) => Rank2.DistributiveTraversable (Data.Functor.Product.Product g h)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.DistributiveTraversable f => Rank2.DistributiveTraversable (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.DistributiveTraversable f => Rank2.DistributiveTraversable (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.DistributiveTraversable f, Rank2.DistributiveTraversable g) => Rank2.DistributiveTraversable (f GHC.Generics.:*: g)
instance Rank2.Distributive Data.Proxy.Proxy
instance GHC.Base.Monoid x => Rank2.DistributiveTraversable (Data.Functor.Const.Const x)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Distributive g, Rank2.Distributive h) => Rank2.Distributive (Data.Functor.Product.Product g h)
instance GHC.Base.Monoid c => Rank2.DistributiveTraversable (GHC.Generics.K1 i c)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.Distributive f => Rank2.Distributive (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.Distributive f => Rank2.Distributive (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Distributive f, Rank2.Distributive g) => Rank2.Distributive (f GHC.Generics.:*: g)
instance Rank2.Applicative Data.Proxy.Proxy
instance (GHC.Base.Semigroup x, GHC.Base.Monoid x) => Rank2.Applicative (Data.Functor.Const.Const x)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Applicative g, Rank2.Applicative h) => Rank2.Applicative (Data.Functor.Product.Product g h)
instance (GHC.Base.Semigroup c, GHC.Base.Monoid c) => Rank2.Applicative (GHC.Generics.K1 i c)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.Applicative f => Rank2.Applicative (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.Applicative f => Rank2.Applicative (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Applicative f, Rank2.Applicative g) => Rank2.Applicative (f GHC.Generics.:*: g)
instance Rank2.Apply Data.Proxy.Proxy
instance GHC.Base.Semigroup x => Rank2.Apply (Data.Functor.Const.Const x)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Apply g, Rank2.Apply h) => Rank2.Apply (Data.Functor.Product.Product g h)
instance Rank2.Apply GHC.Generics.V1
instance Rank2.Apply GHC.Generics.U1
instance GHC.Base.Semigroup c => Rank2.Apply (GHC.Generics.K1 i c)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.Apply f => Rank2.Apply (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.Apply f => Rank2.Apply (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Apply f, Rank2.Apply g) => Rank2.Apply (f GHC.Generics.:*: g)
instance Rank2.Traversable Data.Proxy.Proxy
instance Rank2.Traversable (Data.Functor.Const.Const x)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Traversable g, Rank2.Traversable h) => Rank2.Traversable (Data.Functor.Product.Product g h)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Traversable g, Rank2.Traversable h) => Rank2.Traversable (Data.Functor.Sum.Sum g h)
instance Rank2.Traversable GHC.Generics.V1
instance Rank2.Traversable GHC.Generics.U1
instance Rank2.Traversable (GHC.Generics.K1 i c)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.Traversable f => Rank2.Traversable (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.Traversable f => Rank2.Traversable (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Traversable f, Rank2.Traversable g) => Rank2.Traversable (f GHC.Generics.:+: g)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Traversable f, Rank2.Traversable g) => Rank2.Traversable (f GHC.Generics.:*: g)
instance Rank2.Foldable Data.Proxy.Proxy
instance Rank2.Foldable (Data.Functor.Const.Const x)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Foldable g, Rank2.Foldable h) => Rank2.Foldable (Data.Functor.Product.Product g h)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Foldable g, Rank2.Foldable h) => Rank2.Foldable (Data.Functor.Sum.Sum g h)
instance Rank2.Foldable GHC.Generics.V1
instance Rank2.Foldable GHC.Generics.U1
instance Rank2.Foldable (GHC.Generics.K1 i c)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.Foldable f => Rank2.Foldable (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.Foldable f => Rank2.Foldable (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Foldable f, Rank2.Foldable g) => Rank2.Foldable (f GHC.Generics.:+: g)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Foldable f, Rank2.Foldable g) => Rank2.Foldable (f GHC.Generics.:*: g)
instance Rank2.Functor Data.Proxy.Proxy
instance Rank2.Functor (Data.Functor.Const.Const a)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Functor g, Rank2.Functor h) => Rank2.Functor (Data.Functor.Product.Product g h)
instance forall k (g :: (k -> *) -> *) (h :: (k -> *) -> *). (Rank2.Functor g, Rank2.Functor h) => Rank2.Functor (Data.Functor.Sum.Sum g h)
instance Rank2.Functor GHC.Generics.V1
instance Rank2.Functor GHC.Generics.U1
instance Rank2.Functor (GHC.Generics.K1 i c)
instance forall k (f :: (k -> *) -> *) i (c :: GHC.Generics.Meta). Rank2.Functor f => Rank2.Functor (GHC.Generics.M1 i c f)
instance forall k (f :: (k -> *) -> *). Rank2.Functor f => Rank2.Functor (GHC.Generics.Rec1 f)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Functor f, Rank2.Functor g) => Rank2.Functor (f GHC.Generics.:+: g)
instance forall k (f :: (k -> *) -> *) (g :: (k -> *) -> *). (Rank2.Functor f, Rank2.Functor g) => Rank2.Functor (f GHC.Generics.:*: g)


-- | This module exports the templates for automatic instance deriving of
--   <a>Rank2</a> type classes. The most common way to use it would be
--   
--   <pre>
--   import qualified Rank2.TH
--   data MyDataType f = ...
--   $(Rank2.TH.deriveAll ''MyDataType)
--   </pre>
--   
--   or, if you're picky, you can invoke only <a>deriveFunctor</a> and
--   whichever other instances you need instead.
module Rank2.TH
deriveAll :: Name -> Q [Dec]
deriveFunctor :: Name -> Q [Dec]
deriveApply :: Name -> Q [Dec]
unsafeDeriveApply :: Name -> Q [Dec]
deriveApplicative :: Name -> Q [Dec]
deriveFoldable :: Name -> Q [Dec]
deriveTraversable :: Name -> Q [Dec]
deriveDistributive :: Name -> Q [Dec]
deriveDistributiveTraversable :: Name -> Q [Dec]
instance GHC.Show.Show Rank2.TH.Deriving
