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


-- | Classes for working with types that can change clothes.
--   
--   Types that are parametric on a functor are like Barbies that have an
--   outfit for each role. This package provides the basic abstractions to
--   work with them comfortably.
@package barbies
@version 2.1.1.0


-- | Sometimes one needs a type like <tt>Barbie <a>Identity</a></tt> and it
--   may feel like a second-class record type, where one needs to unpack
--   values in each field. For those cases, we can leverage on closed
--   type-families:
--   
--   <pre>
--   data <a>Bare</a>
--   data <a>Covered</a>
--   
--   type family <a>Wear</a> t f a where
--     <a>Wear</a> <a>Bare</a>    f a = a
--     <a>Wear</a> <a>Covered</a> f a = f a
--   
--   data SignUpForm t f
--     = SignUpForm
--         { username  :: <a>Wear</a> t f <a>String</a>,
--         , password  :: <a>Wear</a> t f <a>String</a>
--         , mailingOk :: <a>Wear</a> t f <a>Bool</a>
--         }
--    instance <a>FunctorB</a> (SignUpForm <a>Covered</a>)
--    instance <a>TraversableB</a> (SignUpForm <a>Covered</a>)
--    ...,
--    instance <a>BareB</a> SignUpForm
--   
--   type SignUpRaw  = SignUpForm <a>Covered</a> <a>Maybe</a>
--   type SignUpData = SignUpForm <a>Bare</a> <tt>Identity</tt>
--   
--   formData = SignUpForm "jbond" "shaken007" False :: SignUpData
--   </pre>
module Barbies.Bare

-- | The <a>Wear</a> type-function allows one to define a Barbie-type as
--   
--   <pre>
--   data B t f
--     = B { f1 :: <a>Wear</a> t f <a>Int</a>
--         , f2 :: <a>Wear</a> t f <a>Bool</a>
--         }
--   </pre>
--   
--   This gives rise to two rather different types:
--   
--   <ul>
--   <li><tt>B <a>Covered</a> f</tt> is a normal Barbie-type, in the sense
--   that <tt>f1 :: B <a>Covered</a> f -&gt; f <a>Int</a></tt>, etc.</li>
--   <li><tt>B <a>Bare</a> f</tt>, on the other hand, is a normal record
--   with no functor around the type:</li>
--   </ul>
--   
--   <pre>
--   B { f1 :: 5, f2 = <a>True</a> } :: B <a>Bare</a> f
--   </pre>
type family Wear t (f :: Type -> Type) a
data Bare
data Covered

-- | Class of Barbie-types defined using <a>Wear</a> and can therefore have
--   <a>Bare</a> versions. Must satisfy:
--   
--   <pre>
--   <a>bcover</a> . <a>bstrip</a> = <a>id</a>
--   <a>bstrip</a> . <a>bcover</a> = <a>id</a>
--   </pre>
class FunctorB b Covered => BareB (b :: Type -> Type -> Type -> Type)
bstrip :: BareB b => b Covered Identity -> b Bare Identity
($dmbstrip) :: (BareB b, CanDeriveBareB b) => b Covered Identity -> b Bare Identity
bcover :: BareB b => b Bare Identity -> b Covered Identity
($dmbcover) :: (BareB b, CanDeriveBareB b) => b Bare Identity -> b Covered Identity

-- | Generalization of <a>bstrip</a> to arbitrary functors
bstripFrom :: BareB b => (forall a. () => f a -> a) -> b Covered f -> b Bare Identity

-- | Generalization of <a>bcover</a> to arbitrary functors
bcoverWith :: BareB b => (forall a. () => a -> f a) -> b Bare Identity -> b Covered f

-- | Like the <a>Wear</a> family, but with two wrappers <tt>f</tt> and
--   <tt>g</tt> instead of one. This is useful if you have a data-type
--   where <tt>f</tt> is parametric but <tt>g</tt> is not, consider this:
--   
--   <pre>
--   data T t f =
--     T { f1 :: <a>Wear</a>    t f [Bool]
--       , f2 :: <a>Wear</a>    t f (Sum Int)
--       , f3 :: <a>WearTwo</a> t f Sum Int
--       , f4 :: <a>WearTwo</a> t f Max Int
--       }
--   </pre>
--   
--   with <tt>x :: T Covered Option</tt> we would have
--   
--   <pre>
--   f1 x :: IO (Option [Bool])
--   f2 x :: IO (Option (Sum Int))
--   f3 x :: IO (Option (Sum Int))
--   f4 x :: IO (Option (Max Int))
--   </pre>
--   
--   and with <tt>y :: T Bare Identity</tt> we would have
--   
--   <pre>
--   f1 y :: Int
--   f2 y :: Sum Int
--   f3 y :: Int
--   f4 y :: Int
--   </pre>
--   
--   Note how <tt>(Option (Sum Int))</tt> (or <tt>Max</tt>) has a nice
--   Semigroup instance that we can use to merge two (covered) barbies,
--   while <a>WearTwo</a> removes the wrapper for the bare barbie.
type family WearTwo t (f :: Type -> Type) (g :: Type -> Type) a


-- | Functors on indexed-types.
module Data.Functor.Transformer

-- | Functor from indexed-types to indexed-types. Instances of
--   <a>FunctorT</a> should satisfy the following laws:
--   
--   <pre>
--   <a>tmap</a> <a>id</a> = <a>id</a>
--   <a>tmap</a> f . <a>tmap</a> g = <a>tmap</a> (f . g)
--   </pre>
--   
--   There is a default <a>tmap</a> implementation for <a>Generic</a>
--   types, so instances can derived automatically.
class FunctorT (t :: k -> Type -> k' -> Type)
tmap :: forall f g (x :: k'). FunctorT t => (forall (a :: k). () => f a -> g a) -> t f x -> t g x
($dmtmap) :: forall f g (x :: k'). (FunctorT t, CanDeriveFunctorT t f g x) => (forall (a :: k). () => f a -> g a) -> t f x -> t g x

-- | Indexed-functors that can be traversed from left to right. Instances
--   should satisfy the following laws:
--   
--   <pre>
--    t . <a>ttraverse</a> f   = <a>ttraverse</a> (t . f)  -- naturality
--   <a>ttraverse</a> <a>Identity</a> = <a>Identity</a>           -- identity
--   <a>ttraverse</a> (<a>Compose</a> . <a>fmap</a> g . f) = <a>Compose</a> . <a>fmap</a> (<a>ttraverse</a> g) . <a>ttraverse</a> f -- composition
--   </pre>
--   
--   There is a default <a>ttraverse</a> implementation for <a>Generic</a>
--   types, so instances can derived automatically.
class FunctorT t => TraversableT (t :: k -> Type -> k' -> Type)
ttraverse :: forall e f g (x :: k'). (TraversableT t, Applicative e) => (forall (a :: k). () => f a -> e (g a)) -> t f x -> e (t g x)
($dmttraverse) :: forall e f g (x :: k'). (TraversableT t, Applicative e, CanDeriveTraversableT t f g x) => (forall (a :: k). () => f a -> e (g a)) -> t f x -> e (t g x)

-- | <a>ttraverse</a> with the arguments flipped. Useful when the
--   traversing function is a large lambda:
--   
--   <pre>
--   tfor someTransformer $ fa -&gt; ...
--   </pre>
tfor :: forall {k} {k'} t e f (x :: k') g. (TraversableT t, Applicative e) => t f x -> (forall (a :: k). () => f a -> e (g a)) -> e (t g x)

-- | Map each element to an action, evaluate these actions from left to
--   right, and ignore the results.
ttraverse_ :: forall {k} {k'} t e f c (x :: k'). (TraversableT t, Applicative e) => (forall (a :: k). () => f a -> e c) -> t f x -> e ()

-- | <a>ttraverse_</a> with the arguments flipped.
tfor_ :: forall {k} {k'} t e f (x :: k') c. (TraversableT t, Applicative e) => t f x -> (forall (a :: k). () => f a -> e c) -> e ()

-- | Map each element to a monoid, and combine the results.
tfoldMap :: forall {k} {k'} t m f (x :: k'). (TraversableT t, Monoid m) => (forall (a :: k). () => f a -> m) -> t f x -> m

-- | Evaluate each action in the structure from left to right, and collect
--   the results.
tsequence :: forall {k} {k'} e t (f :: k -> Type) (x :: k'). (Applicative e, TraversableT t) => t (Compose e f) x -> e (t f x)

-- | A version of <a>tsequence</a> with <tt>f</tt> specialized to
--   <a>Identity</a>.
tsequence' :: forall {k'} e t (x :: k'). (Applicative e, TraversableT t) => t e x -> e (t Identity x)

-- | A <a>FunctorT</a> where the effects can be distributed to the fields:
--   <a>tdistribute</a> turns an effectful way of building a
--   transformer-type into a pure transformer-type with effectful ways of
--   computing the values of its fields.
--   
--   This class is the categorical dual of <a>TraversableT</a>, with
--   <a>tdistribute</a> the dual of <a>tsequence</a> and <a>tcotraverse</a>
--   the dual of <a>ttraverse</a>. As such, instances need to satisfy these
--   laws:
--   
--   <pre>
--   <a>tdistribute</a> . h = <a>tmap</a> (<a>Compose</a> . h . <a>getCompose</a>) . <a>tdistribute</a>    -- naturality
--   <a>tdistribute</a> . <a>Identity</a> = <a>tmap</a> (<a>Compose</a> . <a>Identity</a>)                 -- identity
--   <a>tdistribute</a> . <a>Compose</a> = <a>fmap</a> (<a>Compose</a> . <a>Compose</a> . <a>fmap</a> <a>getCompose</a> . <a>getCompose</a>) . <a>tdistribute</a> . <a>fmap</a> <a>distribute</a> -- composition
--   </pre>
--   
--   By specializing <tt>f</tt> to <tt>((-&gt;) a)</tt> and <tt>g</tt> to
--   <a>Identity</a>, we can define a function that decomposes a function
--   on distributive transformers into a collection of simpler functions:
--   
--   <pre>
--   <a>tdecompose</a> :: <a>DistributiveT</a> b =&gt; (a -&gt; b <a>Identity</a>) -&gt; b ((-&gt;) a)
--   <a>tdecompose</a> = <a>tmap</a> (<a>fmap</a> <a>runIdentity</a> . <a>getCompose</a>) . <a>tdistribute</a>
--   </pre>
--   
--   Lawful instances of the class can then be characterized as those that
--   satisfy:
--   
--   <pre>
--   <a>trecompose</a> . <a>tdecompose</a> = <a>id</a>
--   <a>tdecompose</a> . <a>trecompose</a> = <a>id</a>
--   </pre>
--   
--   This means intuitively that instances need to have a fixed shape (i.e.
--   no sum-types can be involved). Typically, this means record types, as
--   long as they don't contain fields where the functor argument is not
--   applied.
--   
--   There is a default implementation of <a>tdistribute</a> based on
--   <a>Generic</a>. Intuitively, it works on product types where the shape
--   of a pure value is uniquely defined and every field is covered by the
--   argument <tt>f</tt>.
class FunctorT t => DistributiveT (t :: Type -> Type -> i -> Type)
tdistribute :: forall f (g :: Type -> Type) (x :: i). (DistributiveT t, Functor f) => f (t g x) -> t (Compose f g) x
($dmtdistribute) :: forall f (g :: Type -> Type) (x :: i). (DistributiveT t, CanDeriveDistributiveT t f g x) => f (t g x) -> t (Compose f g) x

-- | A version of <a>tdistribute</a> with <tt>g</tt> specialized to
--   <a>Identity</a>.
tdistribute' :: forall {i} t f (x :: i). (DistributiveT t, Functor f) => f (t Identity x) -> t f x

-- | Dual of <a>ttraverse</a>
tcotraverse :: forall {i} t f g (x :: i). (DistributiveT t, Functor f) => (forall a. () => f (g a) -> f a) -> f (t g x) -> t f x

-- | Decompose a function returning a distributive transformer, into a
--   collection of simpler functions.
tdecompose :: forall {i} t a (x :: i). DistributiveT t => (a -> t Identity x) -> t ((->) a) x

-- | Recompose a decomposed function.
trecompose :: forall {k'} t a (x :: k'). FunctorT t => t ((->) a) x -> a -> t Identity x

-- | A <a>FunctorT</a> with application, providing operations to:
--   
--   <ul>
--   <li>embed an "empty" value (<a>tpure</a>)</li>
--   <li>align and combine values (<a>tprod</a>)</li>
--   </ul>
--   
--   It should satisfy the following laws:
--   
--   <ul>
--   <li><i>Naturality of <a>tprod</a></i></li>
--   </ul>
--   
--   <pre>
--   <a>tmap</a> ((<a>Pair</a> a b) -&gt; <a>Pair</a> (f a) (g b)) (u `<tt>tprod'</tt> v) = <a>tmap</a> f u `<tt>tprod'</tt> <a>tmap</a> g v
--   </pre>
--   
--   <ul>
--   <li><i>Left and right identity</i></li>
--   </ul>
--   
--   <pre>
--   <a>tmap</a> ((<a>Pair</a> _ b) -&gt; b) (<a>tpure</a> e `<tt>tprod'</tt> v) = v
--   <a>tmap</a> ((<a>Pair</a> a _) -&gt; a) (u `<tt>tprod'</tt> <a>tpure</a> e) = u
--   </pre>
--   
--   <ul>
--   <li><i>Associativity</i></li>
--   </ul>
--   
--   <pre>
--   <a>tmap</a> ((<a>Pair</a> a (<a>Pair</a> b c)) -&gt; <a>Pair</a> (<a>Pair</a> a b) c) (u `<tt>tprod'</tt> (v `<tt>tprod'</tt> w)) = (u `<tt>tprod'</tt> v) `<tt>tprod'</tt> w
--   </pre>
--   
--   It is to <a>FunctorT</a> in the same way is <a>Applicative</a> relates
--   to <a>Functor</a>. For a presentation of <a>Applicative</a> as a
--   monoidal functor, see Section 7 of <a>Applicative Programming with
--   Effects</a>.
--   
--   There is a default implementation of <a>tprod</a> and <a>tpure</a>
--   based on <a>Generic</a>. Intuitively, it works on types where the
--   value of <a>tpure</a> is uniquely defined. This corresponds rougly to
--   record types (in the presence of sums, there would be several
--   candidates for <a>tpure</a>), where every field is either a
--   <a>Monoid</a> or covered by the argument <tt>f</tt>.
class FunctorT t => ApplicativeT (t :: k -> Type -> k' -> Type)
tpure :: forall f (x :: k'). ApplicativeT t => (forall (a :: k). () => f a) -> t f x
($dmtpure) :: forall f (x :: k'). (ApplicativeT t, CanDeriveApplicativeT t f f x) => (forall (a :: k). () => f a) -> t f x
tprod :: forall (f :: k -> Type) (x :: k') (g :: k -> Type). ApplicativeT t => t f x -> t g x -> t (Product f g) x
($dmtprod) :: forall (f :: k -> Type) (g :: k -> Type) (x :: k'). (ApplicativeT t, CanDeriveApplicativeT t f g x) => t f x -> t g x -> t (Product f g) x

-- | An alias of <a>tprod</a>.
tzip :: forall {k} {k'} t (f :: k -> Type) (x :: k') (g :: k -> Type). ApplicativeT t => t f x -> t g x -> t (Product f g) x

-- | An equivalent of <a>unzip</a>.
tunzip :: forall {k} {k'} t (f :: k -> Type) (g :: k -> Type) (x :: k'). ApplicativeT t => t (Product f g) x -> (t f x, t g x)

-- | An equivalent of <a>zipWith</a>.
tzipWith :: forall {k} {k'} t f g h (x :: k'). ApplicativeT t => (forall (a :: k). () => f a -> g a -> h a) -> t f x -> t g x -> t h x

-- | An equivalent of <a>zipWith3</a>.
tzipWith3 :: forall {k} {k'} t f g h i (x :: k'). ApplicativeT t => (forall (a :: k). () => f a -> g a -> h a -> i a) -> t f x -> t g x -> t h x -> t i x

-- | An equivalent of <a>zipWith4</a>.
tzipWith4 :: forall {k} {k'} t f g h i j (x :: k'). ApplicativeT t => (forall (a :: k). () => f a -> g a -> h a -> i a -> j a) -> t f x -> t g x -> t h x -> t i x -> t j x

-- | Some endo-functors on indexed-types are monads. Common examples would
--   be "functor-transformers", like <a>Compose</a> or <a>ReaderT</a>. In
--   that sense, <a>MonadT</a> is similar to <a>MonadTrans</a> but with
--   additional structure (see also <a>mmorph</a>'s <tt>MMonad</tt> class).
--   
--   Notice though that while <a>lift</a> assumes a <a>Monad</a> instance
--   of the value to be lifted, <a>tlift</a> has no such constraint. This
--   means we cannot have instances for most "monad transformers", since
--   lifting typically involves an <a>fmap</a>.
--   
--   <a>MonadT</a> also corresponds to the indexed-monad of <a>Kleisli
--   arrows of outrageous fortune</a>.
--   
--   Instances of this class should to satisfy the monad laws. They laws
--   can stated either in terms of <tt>(<a>tlift</a>, <a>tjoin</a>)</tt> or
--   <tt>(<a>tlift</a>, <a>tembed</a>)</tt>. In the former:
--   
--   <pre>
--   <a>tmap</a> h . <a>tlift</a> = <a>tlift</a> . h
--   <a>tmap</a> h . <a>tjoin</a> = <a>tjoin</a> . <a>tmap</a> (<a>tmap</a> h)
--   <a>tjoin</a> . <a>tlift</a>  = <a>id</a>
--   <a>tjoin</a> . 'tmap tlift' = <a>id</a>
--   <a>tjoin</a> . <a>tjoin</a> = <a>tjoin</a> . <a>tmap</a> <a>tjoin</a>
--   </pre>
--   
--   In the latter:
--   
--   <pre>
--   <a>tembed</a> f . <a>tlift</a> = f
--   <a>tembed</a> <a>tlift</a> = <a>id</a>
--   <a>tembed</a> f . <a>tembed</a> g = <a>tembed</a> (<a>tembed</a> f . g)
--   </pre>
class FunctorT t => MonadT (t :: k' -> Type -> k' -> Type)

-- | Lift a functor to a transformed functor.
tlift :: forall f (a :: k'). MonadT t => f a -> t f a

-- | The conventional monad join operator. It is used to remove one level
--   of monadic structure, projecting its bound argument into the outer
--   level.
tjoin :: forall (f :: k' -> Type) (a :: k'). MonadT t => t (t f) a -> t f a

-- | Analogous to <tt>(<a>=&lt;&lt;</a>)</tt>.
tembed :: forall f (g :: k' -> Type) (a :: k'). (MonadT t, MonadT t) => (forall (x :: k'). () => f x -> t g x) -> t f a -> t g a

-- | Instances of this class provide means to talk about constraints, both
--   at compile-time, using <a>AllT</a>, and at run-time, in the form of
--   <a>Dict</a>, via <a>taddDicts</a>.
--   
--   A manual definition would look like this:
--   
--   <pre>
--   data T f a = A (f <a>Int</a>) (f <a>String</a>) | B (f <a>Bool</a>) (f <a>Int</a>)
--   
--   instance <a>ConstraintsT</a> T where
--     type <a>AllT</a> c T = (c <a>Int</a>, c <a>String</a>, c <a>Bool</a>)
--   
--     <a>taddDicts</a> t = case t of
--       A x y -&gt; A (<a>Pair</a> <a>Dict</a> x) (<a>Pair</a> <a>Dict</a> y)
--       B z w -&gt; B (<a>Pair</a> <a>Dict</a> z) (<a>Pair</a> <a>Dict</a> w)
--   </pre>
--   
--   Now, when we given a <tt>T f</tt>, if we need to use the <a>Show</a>
--   instance of their fields, we can use:
--   
--   <pre>
--   <a>taddDicts</a> :: AllT Show t =&gt; t f -&gt; t (<a>Dict</a> <a>Show</a> `<tt>Product'</tt> f)
--   </pre>
--   
--   There is a default implementation of <a>ConstraintsT</a> for
--   <a>Generic</a> types, so in practice one will simply do:
--   
--   <pre>
--   derive instance <a>Generic</a> (T f a)
--   instance <a>ConstraintsT</a> T
--   </pre>
class FunctorT t => ConstraintsT (t :: kl -> Type -> kr -> Type) where {
    
    -- | <tt><a>AllT</a> c t</tt> should contain a constraint <tt>c a</tt> for
    --   each <tt>a</tt> occurring under an <tt>f</tt> in <tt>t f</tt>.
    --   
    --   For requiring constraints of the form <tt>c (f a)</tt>, use
    --   <a>AllTF</a>.
    type AllT (c :: k -> Constraint) (t :: kl -> Type -> kr -> Type);
    type AllT c :: k -> Constraint t :: kl -> Type -> kr -> Type = GAll 1 c GAllRepT t;
}
taddDicts :: forall (c :: kl -> Constraint) (f :: kl -> Type) (x :: kr). (ConstraintsT t, AllT c t) => t f x -> t (Product (Dict c) f) x
($dmtaddDicts) :: forall (c :: kl -> Constraint) (f :: kl -> Type) (x :: kr). (ConstraintsT t, CanDeriveConstraintsT c t f x, AllT c t) => t f x -> t (Product (Dict c) f) x

-- | Similar to <a>AllT</a> but will put the functor argument <tt>f</tt>
--   between the constraint <tt>c</tt> and the type <tt>a</tt>.
type AllTF (c :: k -> Constraint) (f :: k1 -> k) (t :: kl -> Type -> kr -> Type) = AllT ClassF c f t

-- | Like <a>tmap</a> but a constraint is allowed to be required on each
--   element of <tt>t</tt>.
tmapC :: forall {k} {kr} c t f g (x :: kr). (AllT c t, ConstraintsT t) => (forall (a :: k). c a => f a -> g a) -> t f x -> t g x

-- | Like <a>ttraverse</a> but with a constraint on the elements of
--   <tt>t</tt>.
ttraverseC :: forall {k} {kr} c t f g e (x :: kr). (TraversableT t, ConstraintsT t, AllT c t, Applicative e) => (forall (a :: k). c a => f a -> e (g a)) -> t f x -> e (t g x)

-- | Like <a>ttraverseC</a> but with the arguments flipped.
tforC :: forall {kl} {kr} c t f g e (x :: kr). (TraversableT t, ConstraintsT t, AllT c t, Applicative e) => t f x -> (forall (a :: kl). c a => f a -> e (g a)) -> e (t g x)
newtype Rec p a (x :: k)
Rec :: K1 R a x -> Rec p a (x :: k)
[unRec] :: Rec p a (x :: k) -> K1 R a x


-- | Functors from indexed-types to types.
module Data.Functor.Barbie

-- | Barbie-types that can be mapped over. Instances of <a>FunctorB</a>
--   should satisfy the following laws:
--   
--   <pre>
--   <a>bmap</a> <a>id</a> = <a>id</a>
--   <a>bmap</a> f . <a>bmap</a> g = <a>bmap</a> (f . g)
--   </pre>
--   
--   There is a default <a>bmap</a> implementation for <a>Generic</a>
--   types, so instances can derived automatically.
class FunctorB (b :: k -> Type -> Type)
bmap :: FunctorB b => (forall (a :: k). () => f a -> g a) -> b f -> b g
($dmbmap) :: forall f g. (FunctorB b, CanDeriveFunctorB b f g) => (forall (a :: k). () => f a -> g a) -> b f -> b g

-- | Barbie-types that can be traversed from left to right. Instances
--   should satisfy the following laws:
--   
--   <pre>
--    t . <a>btraverse</a> f   = <a>btraverse</a> (t . f)  -- naturality
--   <a>btraverse</a> <a>Identity</a> = <a>Identity</a>           -- identity
--   <a>btraverse</a> (<a>Compose</a> . <a>fmap</a> g . f) = <a>Compose</a> . <a>fmap</a> (<a>btraverse</a> g) . <a>btraverse</a> f -- composition
--   </pre>
--   
--   There is a default <a>btraverse</a> implementation for <a>Generic</a>
--   types, so instances can derived automatically.
class FunctorB b => TraversableB (b :: k -> Type -> Type)
btraverse :: (TraversableB b, Applicative e) => (forall (a :: k). () => f a -> e (g a)) -> b f -> e (b g)
($dmbtraverse) :: forall e f g. (TraversableB b, Applicative e, CanDeriveTraversableB b f g) => (forall (a :: k). () => f a -> e (g a)) -> b f -> e (b g)

-- | <a>btraverse</a> with the arguments flipped. Useful when the
--   traversing function is a large lambda:
--   
--   <pre>
--   bfor someBarbie $ fa -&gt; ...
--   </pre>
bfor :: (TraversableB b, Applicative e) => b f -> (forall (a :: k). () => f a -> e (g a)) -> e (b g)

-- | Map each element to an action, evaluate these actions from left to
--   right, and ignore the results.
btraverse_ :: (TraversableB b, Applicative e) => (forall (a :: k). () => f a -> e c) -> b f -> e ()

-- | <a>btraverse_</a> with the arguments flipped.
bfor_ :: (TraversableB b, Applicative e) => b f -> (forall (a :: k). () => f a -> e c) -> e ()

-- | Map each element to a monoid, and combine the results.
bfoldMap :: (TraversableB b, Monoid m) => (forall (a :: k). () => f a -> m) -> b f -> m

-- | Evaluate each action in the structure from left to right, and collect
--   the results.
bsequence :: forall {k} e b (f :: k -> Type). (Applicative e, TraversableB b) => b (Compose e f) -> e (b f)

-- | A version of <a>bsequence</a> with <tt>f</tt> specialized to
--   <a>Identity</a>.
bsequence' :: (Applicative e, TraversableB b) => b e -> e (b Identity)

-- | A <a>FunctorB</a> where the effects can be distributed to the fields:
--   <a>bdistribute</a> turns an effectful way of building a Barbie-type
--   into a pure Barbie-type with effectful ways of computing the values of
--   its fields.
--   
--   This class is the categorical dual of <a>TraversableB</a>, with
--   <a>bdistribute</a> the dual of <a>bsequence</a> and <a>bcotraverse</a>
--   the dual of <a>btraverse</a>. As such, instances need to satisfy these
--   laws:
--   
--   <pre>
--   <a>bdistribute</a> . h = <a>bmap</a> (<a>Compose</a> . h . <a>getCompose</a>) . <a>bdistribute</a>    -- naturality
--   <a>bdistribute</a> . <a>Identity</a> = <a>bmap</a> (<a>Compose</a> . <a>Identity</a>)                 -- identity
--   <a>bdistribute</a> . <a>Compose</a> = <a>bmap</a> (<a>Compose</a> . <a>Compose</a> . <a>fmap</a> <a>getCompose</a> . <a>getCompose</a>) . <a>bdistribute</a> . <a>fmap</a> <a>bdistribute</a> -- composition
--   </pre>
--   
--   By specializing <tt>f</tt> to <tt>((-&gt;) a)</tt> and <tt>g</tt> to
--   <a>Identity</a>, we can define a function that decomposes a function
--   on distributive barbies into a collection of simpler functions:
--   
--   <pre>
--   <a>bdecompose</a> :: <a>DistributiveB</a> b =&gt; (a -&gt; b <a>Identity</a>) -&gt; b ((-&gt;) a)
--   <a>bdecompose</a> = <a>bmap</a> (<a>fmap</a> <a>runIdentity</a> . <a>getCompose</a>) . <a>bdistribute</a>
--   </pre>
--   
--   Lawful instances of the class can then be characterized as those that
--   satisfy:
--   
--   <pre>
--   <a>brecompose</a> . <a>bdecompose</a> = <a>id</a>
--   <a>bdecompose</a> . <a>brecompose</a> = <a>id</a>
--   </pre>
--   
--   This means intuitively that instances need to have a fixed shape (i.e.
--   no sum-types can be involved). Typically, this means record types, as
--   long as they don't contain fields where the functor argument is not
--   applied.
--   
--   There is a default implementation of <a>bdistribute</a> based on
--   <a>Generic</a>. Intuitively, it works on product types where the shape
--   of a pure value is uniquely defined and every field is covered by the
--   argument <tt>f</tt>.
class FunctorB b => DistributiveB (b :: k -> Type -> Type)
bdistribute :: forall f (g :: k -> Type). (DistributiveB b, Functor f) => f (b g) -> b (Compose f g)
($dmbdistribute) :: forall f (g :: k -> Type). (DistributiveB b, CanDeriveDistributiveB b f g, Functor f) => f (b g) -> b (Compose f g)

-- | A version of <a>bdistribute</a> with <tt>g</tt> specialized to
--   <a>Identity</a>.
bdistribute' :: (DistributiveB b, Functor f) => f (b Identity) -> b f

-- | Dual of <a>btraverse</a>
bcotraverse :: (DistributiveB b, Functor f) => (forall a. () => f (g a) -> f a) -> f (b g) -> b f

-- | Decompose a function returning a distributive barbie, into a
--   collection of simpler functions.
bdecompose :: DistributiveB b => (a -> b Identity) -> b ((->) a)

-- | Recompose a decomposed function.
brecompose :: FunctorB b => b ((->) a) -> a -> b Identity

-- | A <a>FunctorB</a> with application, providing operations to:
--   
--   <ul>
--   <li>embed an "empty" value (<a>bpure</a>)</li>
--   <li>align and combine values (<a>bprod</a>)</li>
--   </ul>
--   
--   It should satisfy the following laws:
--   
--   <ul>
--   <li><i>Naturality of <a>bprod</a></i></li>
--   </ul>
--   
--   <pre>
--   <a>bmap</a> ((<a>Pair</a> a b) -&gt; <a>Pair</a> (f a) (g b)) (u `<tt>bprod'</tt> v) = <a>bmap</a> f u `<tt>bprod'</tt> <a>bmap</a> g v
--   </pre>
--   
--   <ul>
--   <li><i>Left and right identity</i></li>
--   </ul>
--   
--   <pre>
--   <a>bmap</a> ((<a>Pair</a> _ b) -&gt; b) (<a>bpure</a> e `<tt>bprod'</tt> v) = v
--   <a>bmap</a> ((<a>Pair</a> a _) -&gt; a) (u `<tt>bprod'</tt> <a>bpure</a> e) = u
--   </pre>
--   
--   <ul>
--   <li><i>Associativity</i></li>
--   </ul>
--   
--   <pre>
--   <a>bmap</a> ((<a>Pair</a> a (<a>Pair</a> b c)) -&gt; <a>Pair</a> (<a>Pair</a> a b) c) (u `<tt>bprod'</tt> (v `<tt>bprod'</tt> w)) = (u `<tt>bprod'</tt> v) `<tt>bprod'</tt> w
--   </pre>
--   
--   It is to <a>FunctorB</a> in the same way as <a>Applicative</a> relates
--   to <a>Functor</a>. For a presentation of <a>Applicative</a> as a
--   monoidal functor, see Section 7 of <a>Applicative Programming with
--   Effects</a>.
--   
--   There is a default implementation of <a>bprod</a> and <a>bpure</a>
--   based on <a>Generic</a>. Intuitively, it works on types where the
--   value of <a>bpure</a> is uniquely defined. This corresponds rougly to
--   record types (in the presence of sums, there would be several
--   candidates for <a>bpure</a>), where every field is either a
--   <a>Monoid</a> or covered by the argument <tt>f</tt>.
class FunctorB b => ApplicativeB (b :: k -> Type -> Type)
bpure :: ApplicativeB b => (forall (a :: k). () => f a) -> b f
($dmbpure) :: forall f. (ApplicativeB b, CanDeriveApplicativeB b f f) => (forall (a :: k). () => f a) -> b f
bprod :: forall (f :: k -> Type) (g :: k -> Type). ApplicativeB b => b f -> b g -> b (Product f g)
($dmbprod) :: forall (f :: k -> Type) (g :: k -> Type). (ApplicativeB b, CanDeriveApplicativeB b f g) => b f -> b g -> b (Product f g)

-- | An alias of <a>bprod</a>, since this is like a <a>zip</a>.
bzip :: forall {k} b (f :: k -> Type) (g :: k -> Type). ApplicativeB b => b f -> b g -> b (Product f g)

-- | An equivalent of <a>unzip</a>.
bunzip :: forall {k} b (f :: k -> Type) (g :: k -> Type). ApplicativeB b => b (Product f g) -> (b f, b g)

-- | An equivalent of <a>zipWith</a>.
bzipWith :: ApplicativeB b => (forall (a :: k). () => f a -> g a -> h a) -> b f -> b g -> b h

-- | An equivalent of <a>zipWith3</a>.
bzipWith3 :: ApplicativeB b => (forall (a :: k). () => f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i

-- | An equivalent of <a>zipWith4</a>.
bzipWith4 :: ApplicativeB b => (forall (a :: k). () => f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j

-- | Instances of this class provide means to talk about constraints, both
--   at compile-time, using <a>AllB</a>, and at run-time, in the form of
--   <a>Dict</a>, via <a>baddDicts</a>.
--   
--   A manual definition would look like this:
--   
--   <pre>
--   data T f = A (f <a>Int</a>) (f <a>String</a>) | B (f <a>Bool</a>) (f <a>Int</a>)
--   
--   instance <a>ConstraintsB</a> T where
--     type <a>AllB</a> c T = (c <a>Int</a>, c <a>String</a>, c <a>Bool</a>)
--   
--     <a>baddDicts</a> t = case t of
--       A x y -&gt; A (<a>Pair</a> <a>Dict</a> x) (<a>Pair</a> <a>Dict</a> y)
--       B z w -&gt; B (<a>Pair</a> <a>Dict</a> z) (<a>Pair</a> <a>Dict</a> w)
--   </pre>
--   
--   Now, when we given a <tt>T f</tt>, if we need to use the <a>Show</a>
--   instance of their fields, we can use:
--   
--   <pre>
--   <a>baddDicts</a> :: AllB Show b =&gt; b f -&gt; b (<a>Dict</a> <a>Show</a> `<tt>Product'</tt> f)
--   </pre>
--   
--   There is a default implementation of <a>ConstraintsB</a> for
--   <a>Generic</a> types, so in practice one will simply do:
--   
--   <pre>
--   derive instance <a>Generic</a> (T f)
--   instance <a>ConstraintsB</a> T
--   </pre>
class FunctorB b => ConstraintsB (b :: k -> Type -> Type) where {
    
    -- | <tt><a>AllB</a> c b</tt> should contain a constraint <tt>c a</tt> for
    --   each <tt>a</tt> occurring under an <tt>f</tt> in <tt>b f</tt>. E.g.:
    --   
    --   <pre>
    --   <a>AllB</a> <a>Show</a> Person ~ (<a>Show</a> <a>String</a>, <a>Show</a> <a>Int</a>)
    --   </pre>
    --   
    --   For requiring constraints of the form <tt>c (f a)</tt>, use
    --   <a>AllBF</a>.
    type AllB (c :: k -> Constraint) (b :: k -> Type -> Type);
    type AllB c :: k -> Constraint b :: k -> Type -> Type = GAll 0 c GAllRepB b;
}
baddDicts :: forall (c :: k -> Constraint) (f :: k -> Type). (ConstraintsB b, AllB c b) => b f -> b (Product (Dict c) f)
($dmbaddDicts) :: forall (c :: k -> Constraint) (f :: k -> Type). (ConstraintsB b, CanDeriveConstraintsB c b f, AllB c b) => b f -> b (Product (Dict c) f)

-- | Similar to <a>AllB</a> but will put the functor argument <tt>f</tt>
--   between the constraint <tt>c</tt> and the type <tt>a</tt>. For
--   example:
--   
--   <pre>
--   <a>AllB</a>  <a>Show</a>   Person ~ (<a>Show</a>    <a>String</a>,  <a>Show</a>    <a>Int</a>)
--   <a>AllBF</a> <a>Show</a> f Person ~ (<a>Show</a> (f <a>String</a>), <a>Show</a> (f <a>Int</a>))
--   
--   </pre>
type AllBF (c :: k -> Constraint) (f :: k1 -> k) (b :: k1 -> Type -> Type) = AllB ClassF c f b

-- | Similar to <a>baddDicts</a> but can produce the instance dictionaries
--   "out of the blue".
bdicts :: forall {k} (c :: k -> Constraint) b. (ConstraintsB b, ApplicativeB b, AllB c b) => b (Dict c)

-- | Like <a>bmap</a> but a constraint is allowed to be required on each
--   element of <tt>b</tt>
--   
--   E.g. If all fields of <tt>b</tt> are <a>Show</a>able then you could
--   store each shown value in it's slot using <a>Const</a>:
--   
--   <pre>
--   showFields :: (AllB Show b, ConstraintsB b) =&gt; b Identity -&gt; b (Const String)
--   showFields = bmapC @Show showField
--     where
--       showField :: forall a. Show a =&gt; Identity a -&gt; Const String a
--       showField (Identity a) = Const (show a)
--   </pre>
--   
--   Notice that one can use the <a>(&amp;)</a> class as a way to require
--   several constraiints to hold simultaneously:
--   
--   <pre>
--   bmap @(Show &amp; Eq &amp; Enum) r
--   </pre>
bmapC :: (AllB c b, ConstraintsB b) => (forall (a :: k). c a => f a -> g a) -> b f -> b g
bfoldMapC :: forall {k} c b m f. (TraversableB b, ConstraintsB b, AllB c b, Monoid m) => (forall (a :: k). c a => f a -> m) -> b f -> m

-- | Like <a>btraverse</a> but with a constraint on the elements of
--   <tt>b</tt>.
btraverseC :: forall {k} c b f g e. (TraversableB b, ConstraintsB b, AllB c b, Applicative e) => (forall (a :: k). c a => f a -> e (g a)) -> b f -> e (b g)

-- | <a>btraverseC</a> with the arguments flipped. Useful when the
--   traversing function is a large lambda:
--   
--   <pre>
--   bforC someBarbie $ fa -&gt; ...
--   </pre>
bforC :: forall {k} c b f g e. (TraversableB b, ConstraintsB b, AllB c b, Applicative e) => b f -> (forall (a :: k). c a => f a -> e (g a)) -> e (b g)

-- | Like <a>bpure</a> but a constraint is allowed to be required on each
--   element of <tt>b</tt>.
bpureC :: forall {k} c f b. (AllB c b, ConstraintsB b, ApplicativeB b) => (forall (a :: k). c a => f a) -> b f

-- | Like <a>bzipWith</a> but with a constraint on the elements of
--   <tt>b</tt>.
bzipWithC :: (AllB c b, ConstraintsB b, ApplicativeB b) => (forall (a :: k). c a => f a -> g a -> h a) -> b f -> b g -> b h

-- | Like <a>bzipWith3</a> but with a constraint on the elements of
--   <tt>b</tt>.
bzipWith3C :: (AllB c b, ConstraintsB b, ApplicativeB b) => (forall (a :: k). c a => f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i

-- | Like <a>bzipWith4</a> but with a constraint on the elements of
--   <tt>b</tt>.
bzipWith4C :: (AllB c b, ConstraintsB b, ApplicativeB b) => (forall (a :: k). c a => f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j

-- | Builds a <tt>b f</tt>, by applying <a>mempty</a> on every field of
--   <tt>b</tt>.
bmempty :: forall {k} (f :: k -> Type) b. (AllBF Monoid f b, ConstraintsB b, ApplicativeB b) => b f
newtype Rec p a (x :: k)
Rec :: K1 R a x -> Rec p a (x :: k)
[unRec] :: Rec p a (x :: k) -> K1 R a x

module Barbies.Bi

-- | Map over both arguments at the same time.
btmap :: forall {k1} {k2} b f f' g g'. (FunctorB (b f), FunctorT b) => (forall (a :: k1). () => f a -> f' a) -> (forall (a :: k2). () => g a -> g' a) -> b f g -> b f' g'

-- | A version of <a>btmap</a> specialized to a single argument.
btmap1 :: (FunctorB (b f), FunctorT b) => (forall (a :: k). () => f a -> g a) -> b f f -> b g g

-- | Traverse over both arguments, first over <tt>f</tt>, then over
--   <tt>g</tt>..
bttraverse :: forall {k1} {k2} b f t f' g g'. (TraversableB (b f), TraversableT b, Monad t) => (forall (a :: k1). () => f a -> t (f' a)) -> (forall (a :: k2). () => g a -> t (g' a)) -> b f g -> t (b f' g')

-- | A version of <a>bttraverse</a> specialized to a single argument.
bttraverse1 :: (TraversableB (b f), TraversableT b, Monad t) => (forall (a :: k). () => f a -> t (g a)) -> b f f -> t (b g g)

-- | <a>bttraverse1</a> with the arguments flipped.
btfor1 :: (TraversableB (b f), TraversableT b, Monad t) => b f f -> (forall (a :: k). () => f a -> t (g a)) -> t (b g g)

-- | Map each element to an action, evaluate these actions from left to
--   right and ignore the results.
bttraverse_ :: forall {k1} {k2} b f e c g d. (TraversableB (b f), TraversableT b, Monad e) => (forall (a :: k1). () => f a -> e c) -> (forall (a :: k2). () => g a -> e d) -> b f g -> e ()

-- | Map each element to a monoid, and combine the results.
btfoldMap :: forall {k1} {k2} b f m g. (TraversableB (b f), TraversableT b, Monoid m) => (forall (a :: k1). () => f a -> m) -> (forall (a :: k2). () => g a -> m) -> b f g -> m

-- | Conceptually, this is like simultaneously using <tt>bpure</tt> and
--   <a>tpure</a>.
btpure :: forall {k1} {k2} b f g. (ApplicativeB (b (Unit :: (k1 -> Type) -> Type)), FunctorT b) => (forall (a :: k1 -> Type). () => f a) -> (forall (a :: k2). () => g a) -> b f g

-- | A version of <a>btpure</a> specialized to a single argument.
btpure1 :: (ApplicativeB (b (Unit :: (k -> Type) -> Type)), FunctorT b) => (forall (a :: k -> Type). () => f a) -> b f f

-- | Simultaneous product on both arguments.
btprod :: forall {k} b (f :: Type -> Type) (f' :: Type -> Type) (g :: k -> Type) (g' :: k -> Type). (ApplicativeB (b (Alt (Product f f'))), FunctorT b, Alternative f, Alternative f') => b f g -> b f' g' -> b (Product f f') (Product g g')

-- | Convert a <a>FunctorB</a> into a <a>FunctorT</a> and vice-versa.
newtype Flip (b :: k -> k1 -> Type) (l :: k1) (r :: k)
Flip :: b r l -> Flip (b :: k -> k1 -> Type) (l :: k1) (r :: k)
[runFlip] :: Flip (b :: k -> k1 -> Type) (l :: k1) (r :: k) -> b r l
instance forall k1 k2 (b :: (k1 -> *) -> k2 -> *) (f :: k2). Barbies.Internal.ApplicativeT.ApplicativeT b => Barbies.Internal.ApplicativeB.ApplicativeB (Barbies.Bi.Flip b f)
instance forall k' k (b :: k' -> (k -> *) -> *). (forall (f :: k'). Barbies.Internal.ApplicativeB.ApplicativeB (b f)) => Barbies.Internal.ApplicativeT.ApplicativeT (Barbies.Bi.Flip b)
instance forall k (b :: (* -> *) -> k -> *) (f :: k). Barbies.Internal.DistributiveT.DistributiveT b => Barbies.Internal.DistributiveB.DistributiveB (Barbies.Bi.Flip b f)
instance forall i (b :: i -> (* -> *) -> *). (forall (f :: i). Barbies.Internal.DistributiveB.DistributiveB (b f)) => Barbies.Internal.DistributiveT.DistributiveT (Barbies.Bi.Flip b)
instance forall k1 k2 (b :: k2 -> k1 -> *) (l :: k1) (r :: k2). GHC.Classes.Eq (b r l) => GHC.Classes.Eq (Barbies.Bi.Flip b l r)
instance forall k1 k2 (b :: (k1 -> *) -> k2 -> *) (f :: k2). Barbies.Internal.FunctorT.FunctorT b => Barbies.Internal.FunctorB.FunctorB (Barbies.Bi.Flip b f)
instance forall k' k (b :: k' -> (k -> *) -> *). (forall (f :: k'). Barbies.Internal.FunctorB.FunctorB (b f)) => Barbies.Internal.FunctorT.FunctorT (Barbies.Bi.Flip b)
instance forall k1 k2 (b :: k2 -> k1 -> *) (l :: k1) (r :: k2). GHC.Classes.Ord (b r l) => GHC.Classes.Ord (Barbies.Bi.Flip b l r)
instance forall k1 k2 (b :: k2 -> k1 -> *) (l :: k1) (r :: k2). GHC.Internal.Read.Read (b r l) => GHC.Internal.Read.Read (Barbies.Bi.Flip b l r)
instance forall k1 k2 (b :: k2 -> k1 -> *) (l :: k1) (r :: k2). GHC.Internal.Show.Show (b r l) => GHC.Internal.Show.Show (Barbies.Bi.Flip b l r)
instance forall k1 k2 (b :: (k1 -> *) -> k2 -> *) (f :: k2). Barbies.Internal.TraversableT.TraversableT b => Barbies.Internal.TraversableB.TraversableB (Barbies.Bi.Flip b f)
instance forall k' k (b :: k' -> (k -> *) -> *). (forall (f :: k'). Barbies.Internal.TraversableB.TraversableB (b f)) => Barbies.Internal.TraversableT.TraversableT (Barbies.Bi.Flip b)


-- | A common Haskell idiom is to parameterise a datatype by a functor or
--   GADT (or any "indexed type" <tt>k -&gt; <a>Type</a></tt>), a pattern
--   sometimes called <a>HKD</a>). This parameter acts like the outfit of a
--   Barbie, turning it into a different doll. The canonical example would
--   be:
--   
--   <pre>
--   data Person f
--     = Person
--         { name :: f <a>String</a>
--         , age  :: f <a>Int</a>
--         }
--   </pre>
--   
--   Let's say that we are writing an application where <tt>Person</tt>
--   data will be read from a web form, validated, and stored in a
--   database. Some possibles outfits that we could use along the way are:
--   
--   <pre>
--   Person (<a>Const</a> <a>String</a>)  -- for the raw input from the web-form,
--   Person (<a>Either</a> <a>String</a>) -- for the result of parsing and validating,
--   Person <a>Identity</a>        -- for the actual data,
--   Person DbColumn        -- To describe how to read / write a <tt>Person</tt> to the db
--   
--   data DbColumn a
--     = DbColumn
--         { colName :: <a>String</a>
--         , fromDb  :: DbDataParser a
--         , toDb    :: a -&gt; DbData
--         }
--   </pre>
--   
--   In such application it is likely that one will have lots of types like
--   <tt>Person</tt> so we will like to handle these transformations
--   uniformly, without boilerplate or repetitions. This package provides
--   classes to manipulate these types, using notions that are familiar to
--   haskellers like <a>Functor</a>, <a>Applicative</a> or
--   <a>Traversable</a>. For example, instead of writing an ad-hoc function
--   that checks that all fields have a correct value, like
--   
--   <pre>
--   checkPerson :: Person (<a>Either</a> <a>String</a>) -&gt; <a>Either</a> [<a>String</a>] (Person <a>Identity</a>)
--   </pre>
--   
--   we can write only one such function:
--   
--   <pre>
--   check :: <a>TraversableB</a> b =&gt; b (<a>Either</a> <a>String</a>) -&gt; <a>Either</a> [<a>String</a>] (b <a>Identity</a>)
--   check be
--     = case <a>btraverse</a> (<a>either</a> (<a>const</a> <a>Nothing</a>) (<a>Just</a> . <a>Identity</a>)) be of
--         <a>Just</a> bi -&gt; <a>Right</a> bi
--         <a>Nothing</a> -&gt; <a>Left</a> (<a>bfoldMap</a> (<a>either</a> (:[]) (<a>const</a> [])) be)
--   </pre>
--   
--   Moreover, these classes come with default instances based on
--   <a>Generic</a>, so using them is as easy as:
--   
--   <pre>
--   data Person f
--     = Person
--         { name :: f <a>String</a>
--         , age  :: f <a>Int</a>
--         }
--     deriving
--       ( <a>Generic</a>
--       , <a>FunctorB</a>, <a>TraversableB</a>, <a>ApplicativeB</a>, <a>ConstraintsB</a>
--       )
--   
--   deriving instance <a>AllBF</a> <a>Show</a> f Person =&gt; <a>Show</a> (Person f)
--   deriving instance <a>AllBF</a> <a>Eq</a>   f Person =&gt; <a>Eq</a>   (Person f)
--   </pre>
module Barbies

-- | Wrapper for barbies that act as containers of <tt>a</tt> by wearing
--   <tt>(<a>Const</a> a)</tt>.
newtype Container (b :: Type -> Type -> Type) a
Container :: b (Const a :: Type -> Type) -> Container (b :: (Type -> Type) -> Type) a
[getContainer] :: Container (b :: (Type -> Type) -> Type) a -> b (Const a :: Type -> Type)

-- | Wrapper for barbies that act as containers of <tt>e</tt> by wearing
--   <tt><a>Either</a> e</tt>.
newtype ErrorContainer (b :: Type -> Type -> Type) e
ErrorContainer :: b (Either e) -> ErrorContainer (b :: (Type -> Type) -> Type) e
[getErrorContainer] :: ErrorContainer (b :: (Type -> Type) -> Type) e -> b (Either e)

-- | A wrapper for Barbie-types, providing useful instances.
newtype Barbie (b :: k -> Type -> Type) (f :: k -> Type)
Barbie :: b f -> Barbie (b :: (k -> Type) -> Type) (f :: k -> Type)
[getBarbie] :: Barbie (b :: (k -> Type) -> Type) (f :: k -> Type) -> b f

-- | Uninhabited barbie type.
data Void (f :: k -> Type)

-- | A barbie type without structure.
data Unit (f :: k -> Type)
Unit :: Unit (f :: k -> Type)


-- | Support for operating on Barbie-types with constrained functions.
module Barbies.Constraints

-- | <tt><a>Dict</a> c a</tt> is evidence that there exists an instance of
--   <tt>c a</tt>.
--   
--   It is essentially equivalent to <tt>Dict (c a)</tt> from the
--   <a>constraints</a> package, but because of its kind, it allows us to
--   define things like <tt><a>Dict</a> <a>Show</a></tt>.
data Dict (c :: k -> Constraint) (a :: k)
[Dict] :: forall {k} (c :: k -> Constraint) (a :: k). c a => Dict c a

-- | Turn a constrained-function into an unconstrained one that uses the
--   packed instance dictionary instead.
requiringDict :: forall {k} c (a :: k) r. (c a => r) -> Dict c a -> r

-- | Similar to <a>AllB</a> but will put the functor argument <tt>f</tt>
--   between the constraint <tt>c</tt> and the type <tt>a</tt>. For
--   example:
--   
--   <pre>
--   <a>AllB</a>  <a>Show</a>   Person ~ (<a>Show</a>    <a>String</a>,  <a>Show</a>    <a>Int</a>)
--   <a>AllBF</a> <a>Show</a> f Person ~ (<a>Show</a> (f <a>String</a>), <a>Show</a> (f <a>Int</a>))
--   
--   </pre>
type AllBF (c :: k -> Constraint) (f :: k1 -> k) (b :: k1 -> Type -> Type) = AllB ClassF c f b

-- | <a>ClassF</a> has one universal instance that makes <tt><a>ClassF</a>
--   c f a</tt> equivalent to <tt>c (f a)</tt>. However, we have
--   
--   <pre>
--   'ClassF c f :: k -&gt; <a>Constraint</a>
--   </pre>
--   
--   This is useful since it allows to define constraint-constructors like
--   <tt><a>ClassF</a> <a>Monoid</a> <a>Maybe</a></tt>
class c f a => ClassF (c :: k -> Constraint) (f :: k1 -> k) (a :: k1)

-- | Like <a>ClassF</a> but for binary relations.
class c f a g a => ClassFG (c :: k -> k1 -> Constraint) (f :: k2 -> k) (g :: k2 -> k1) (a :: k2)
class (c a, d a) => ( (c :: k -> Constraint) & (d :: k -> Constraint) ) (a :: k)

module Barbies.Internal

-- | Default implementation of <a>bmap</a> based on <a>Generic</a>.
gbmapDefault :: CanDeriveFunctorB b f g => (forall (a :: k). () => f a -> g a) -> b f -> b g
class GFunctor (n :: Nat) (f :: k -> Type) (g :: k -> Type) (repbf :: k1 -> Type) (repbg :: k1 -> Type)
gmap :: forall (x :: k1). GFunctor n f g repbf repbg => Proxy n -> (forall (a :: k). () => f a -> g a) -> repbf x -> repbg x

-- | <tt><a>CanDeriveFunctorB</a> B f g</tt> is in practice a predicate
--   about <tt>B</tt> only. Intuitively, it says that the following holds,
--   for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (B f)</tt>.</li>
--   <li><tt>B f</tt> can contain fields of type <tt>b f</tt> as long as
--   there exists a <tt><a>FunctorB</a> b</tt> instance. In particular,
--   recursive usages of <tt>B f</tt> are allowed.</li>
--   <li><tt>B f</tt> can also contain usages of <tt>b f</tt> under a
--   <tt><a>Functor</a> h</tt>. For example, one could use <tt><a>Maybe</a>
--   (B f)</tt> when defining <tt>B f</tt>.</li>
--   </ul>
type CanDeriveFunctorB (b :: k -> Type -> Type) (f :: k -> Type) (g :: k -> Type) = (GenericP 0 b f, GenericP 0 b g, GFunctor 0 f g RepP 0 b f RepP 0 b g)

-- | <tt><a>CanDeriveFunctorT</a> T f g x</tt> is in practice a predicate
--   about <tt>T</tt> only. Intuitively, it says that the following holds,
--   for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (T f)</tt>.</li>
--   <li><tt>T f x</tt> can contain fields of type <tt>t f y</tt> as long
--   as there exists a <tt><a>FunctorT</a> t</tt> instance. In particular,
--   recursive usages of <tt>T f y</tt> are allowed.</li>
--   <li><tt>T f x</tt> can also contain usages of <tt>t f y</tt> under a
--   <tt><a>Functor</a> h</tt>. For example, one could use <tt><a>Maybe</a>
--   (T f y)</tt> when defining <tt>T f y</tt>.</li>
--   </ul>
type CanDeriveFunctorT (t :: k -> Type -> k1 -> Type) (f :: k -> Type) (g :: k -> Type) (x :: k1) = (GenericP 1 t f x, GenericP 1 t g x, GFunctor 1 f g RepP 1 t f x RepP 1 t g x)

-- | Default implementation of <a>btraverse</a> based on <a>Generic</a>.
gbtraverseDefault :: forall {k1} b f g e. (Applicative e, CanDeriveTraversableB b f g) => (forall (a :: k1). () => f a -> e (g a)) -> b f -> e (b g)
class GTraversable (n :: k) (f :: k1 -> Type) (g :: k1 -> Type) (repbf :: k2 -> Type) (repbg :: k2 -> Type)
gtraverse :: forall t (x :: k2). (GTraversable n f g repbf repbg, Applicative t) => Proxy n -> (forall (a :: k1). () => f a -> t (g a)) -> repbf x -> t (repbg x)

-- | <tt><a>CanDeriveTraversableB</a> B f g</tt> is in practice a predicate
--   about <tt>B</tt> only. It is analogous to <a>CanDeriveFunctorB</a>, so
--   it essentially requires the following to hold, for any arbitrary
--   <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (B f)</tt>.</li>
--   <li><tt>B f</tt> can contain fields of type <tt>b f</tt> as long as
--   there exists a <tt><a>TraversableB</a> b</tt> instance. In particular,
--   recursive usages of <tt>B f</tt> are allowed.</li>
--   <li><tt>B f</tt> can also contain usages of <tt>b f</tt> under a
--   <tt><a>Traversable</a> h</tt>. For example, one could use
--   <tt><a>Maybe</a> (B f)</tt> when defining <tt>B f</tt>.</li>
--   </ul>
type CanDeriveTraversableB (b :: k1 -> Type -> Type) (f :: k1 -> Type) (g :: k1 -> Type) = (GenericP 0 b f, GenericP 0 b g, GTraversable 0 f g RepP 0 b f RepP 0 b g)

-- | <tt><a>CanDeriveTraversableT</a> T f g x</tt> is in practice a
--   predicate about <tt>T</tt> only. It is analogous to
--   <a>CanDeriveFunctorT</a>, so it essentially requires the following to
--   hold, for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (T f x)</tt>.</li>
--   <li><tt>T f x</tt> can contain fields of type <tt>t f x</tt> as long
--   as there exists a <tt><a>TraversableT</a> t</tt> instance. In
--   particular, recursive usages of <tt>T f x</tt> are allowed.</li>
--   <li><tt>T f x</tt> can also contain usages of <tt>t f x</tt> under a
--   <tt><a>Traversable</a> h</tt>. For example, one could use
--   <tt><a>Maybe</a> (T f x)</tt> when defining <tt>T f x</tt>.</li>
--   </ul>
type CanDeriveTraversableT (t :: k1 -> Type -> k -> Type) (f :: k1 -> Type) (g :: k1 -> Type) (x :: k) = (GenericP 1 t f x, GenericP 1 t g x, GTraversable 1 f g RepP 1 t f x RepP 1 t g x)

-- | Default implementation of <a>bdistribute</a> based on <a>Generic</a>.
gbdistributeDefault :: forall {k1} b f (g :: k1 -> Type). (CanDeriveDistributiveB b f g, Functor f) => f (b g) -> b (Compose f g)
class Functor f => GDistributive (n :: Nat) (f :: Type -> Type) (repbg :: k -> Type) (repbfg :: k -> Type)
gdistribute :: forall (x :: k). GDistributive n f repbg repbfg => Proxy n -> f (repbg x) -> repbfg x

-- | <tt><a>CanDeriveDistributiveB</a> B f g</tt> is in practice a
--   predicate about <tt>B</tt> only. Intuitively, it says the the
--   following holds for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (B f)</tt>.</li>
--   <li><tt>(B f)</tt> has only one constructor, and doesn't contain
--   "naked" fields (that is, not covered by <tt>f</tt>).</li>
--   <li><tt>B f</tt> can contain fields of type <tt>b f</tt> as long as
--   there exists a <tt><a>DistributiveB</a> b</tt> instance. In
--   particular, recursive usages of <tt>B f</tt> are allowed.</li>
--   <li><tt>B f</tt> can also contain usages of <tt>b f</tt> under a
--   <tt><a>Distributive</a> h</tt>. For example, one could use <tt>a -&gt;
--   (B f)</tt> as a field of <tt>B f</tt>.</li>
--   </ul>
type CanDeriveDistributiveB (b :: k1 -> Type -> Type) (f :: Type -> Type) (g :: k1 -> Type) = (GenericP 0 b g, GenericP 0 b Compose f g, GDistributive 0 f RepP 0 b g RepP 0 b Compose f g)

-- | <tt><a>CanDeriveDistributiveT</a> T f g x</tt> is in practice a
--   predicate about <tt>T</tt> only. Intuitively, it says the the
--   following holds for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (B f x)</tt>.</li>
--   <li><tt>(B f x)</tt> has only one constructor, and doesn't contain
--   "naked" fields (that is, not covered by <tt>f</tt>). In particular,
--   <tt>x</tt> needs to occur under <tt>f</tt>.</li>
--   <li><tt>B f x</tt> can contain fields of type <tt>b f y</tt> as long
--   as there exists a <tt><a>DistributiveT</a> b</tt> instance. In
--   particular, recursive usages of <tt>B f x</tt> are allowed.</li>
--   <li><tt>B f x</tt> can also contain usages of <tt>b f y</tt> under a
--   <tt><a>Distributive</a> h</tt>. For example, one could use <tt>a -&gt;
--   (B f x)</tt> as a field of <tt>B f x</tt>.</li>
--   </ul>
type CanDeriveDistributiveT (t :: Type -> Type -> i -> Type) (f :: Type -> Type) (g :: Type -> Type) (x :: i) = (GenericP 1 t g x, GenericP 1 t Compose f g x, GDistributive 1 f RepP 1 t g x RepP 1 t Compose f g x)
gbpureDefault :: CanDeriveApplicativeB b f f => (forall (a :: k). () => f a) -> b f

-- | Default implementation of <a>bprod</a> based on <a>Generic</a>.
gbprodDefault :: forall {k} b (f :: k -> Type) (g :: k -> Type). CanDeriveApplicativeB b f g => b f -> b g -> b (Product f g)
class GApplicative (n :: k) (f :: k2 -> Type) (g :: k2 -> Type) (repbf :: k1 -> Type) (repbg :: k1 -> Type) (repbfg :: k1 -> Type)
gprod :: forall (x :: k1). GApplicative n f g repbf repbg repbfg => Proxy n -> Proxy f -> Proxy g -> repbf x -> repbg x -> repbfg x
gpure :: forall (x :: k1). (GApplicative n f g repbf repbg repbfg, f ~ g, repbf ~ repbg) => Proxy n -> Proxy f -> Proxy repbf -> Proxy repbfg -> (forall (a :: k2). () => f a) -> repbf x

-- | <tt><a>CanDeriveApplicativeB</a> B f g</tt> is in practice a predicate
--   about <tt>B</tt> only. Intuitively, it says that the following holds,
--   for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (B f)</tt>.</li>
--   <li><tt>B</tt> has only one constructor (that is, it is not a
--   sum-type).</li>
--   <li>Every field of <tt>B f</tt> is either a monoid, or of the form
--   <tt>f a</tt>, for some type <tt>a</tt>.</li>
--   </ul>
type CanDeriveApplicativeB (b :: k -> Type -> Type) (f :: k -> Type) (g :: k -> Type) = (GenericP 0 b f, GenericP 0 b g, GenericP 0 b Product f g, GApplicative 0 f g RepP 0 b f RepP 0 b g RepP 0 b Product f g)

-- | <tt><a>CanDeriveApplicativeT</a> T f g x</tt> is in practice a
--   predicate about <tt>T</tt> only. Intuitively, it says that the
--   following holds, for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (T f)</tt>.</li>
--   <li><tt>T</tt> has only one constructor (that is, it is not a
--   sum-type).</li>
--   <li>Every field of <tt>T f x</tt> is either a monoid, or of the form
--   <tt>f a</tt>, for some type <tt>a</tt>.</li>
--   </ul>
type CanDeriveApplicativeT (t :: k -> Type -> k1 -> Type) (f :: k -> Type) (g :: k -> Type) (x :: k1) = (GenericP 1 t f x, GenericP 1 t g x, GenericP 1 t Product f g x, GApplicative 1 f g RepP 1 t f x RepP 1 t g x RepP 1 t Product f g x)

-- | Default implementation of <a>baddDicts</a> based on <a>Generic</a>.
gbaddDictsDefault :: forall {k} b (c :: k -> Constraint) (f :: k -> Type). (CanDeriveConstraintsB c b f, AllB c b) => b f -> b (Product (Dict c) f)
class GConstraints (n :: Nat) (c :: k -> Constraint) (f :: k1) (repbx :: Type -> Type) (repbf :: k2 -> Type) (repbdf :: k2 -> Type)
gaddDicts :: forall (x :: k2). (GConstraints n c f repbx repbf repbdf, GAll n c repbx) => repbf x -> repbdf x

-- | <tt><a>CanDeriveConstraintsB</a> B f g</tt> is in practice a predicate
--   about <tt>B</tt> only. Intuitively, it says that the following holds,
--   for any arbitrary <tt>f</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (B f)</tt>.</li>
--   <li><tt>B f</tt> can contain fields of type <tt>b f</tt> as long as
--   there exists a <tt><a>ConstraintsB</a> b</tt> instance. In particular,
--   recursive usages of <tt>B f</tt> are allowed.</li>
--   </ul>
type CanDeriveConstraintsB (c :: k -> Constraint) (b :: k -> Type -> Type) (f :: k -> Type) = (GenericN b f, GenericN b Product Dict c f, AllB c b ~ GAll 0 c GAllRepB b, GConstraints 0 c f GAllRepB b RepN b f RepN b Product Dict c f)

-- | <tt><a>CanDeriveConstraintsT</a> T f g x</tt> is in practice a
--   predicate about <tt>T</tt> only. Intuitively, it says that the
--   following holds, for any arbitrary <tt>f</tt> and <tt>x</tt>:
--   
--   <ul>
--   <li>There is an instance of <tt><a>Generic</a> (T f x)</tt>.</li>
--   <li><tt>T f</tt> can contain fields of type <tt>t f x</tt> as long as
--   there exists a <tt><a>ConstraintsT</a> t</tt> instance. In particular,
--   recursive usages of <tt>T f x</tt> are allowed.</li>
--   </ul>
type CanDeriveConstraintsT (c :: k -> Constraint) (t :: k -> Type -> kg -> Type) (f :: k -> Type) (x :: kg) = (GenericN t f x, GenericN t Product Dict c f x, AllT c t ~ GAll 1 c GAllRepT t, GConstraints 1 c f GAllRepT t RepN t f x RepN t Product Dict c f x)
type family GAll (n :: Nat) (c :: k -> Constraint) (repbf :: Type -> Type)

-- | The representation used for the generic computation of the
--   <tt><a>AllB</a> c b</tt> constraints.
type GAllRepB (b :: k -> Type -> Type) = TagSelf0 b

-- | The representation used for the generic computation of the
--   <tt><a>AllT</a> c t</tt> constraints. .
type GAllRepT (t :: k -> Type -> kg -> Type) = TagSelf1 t
data X (a :: k)
data family Y :: k
data Self p a x
data Other p a x
type family SelfOrOther (b :: k) (b' :: k) :: Type -> Type -> Type -> Type

-- | We use the type-families to generically compute <tt><a>AllB</a> c
--   b</tt>. Intuitively, if <tt>b' f'</tt> occurs inside <tt>b f</tt>,
--   then we should just add <tt><a>AllB</a> b' c</tt> to <tt><a>AllB</a> b
--   c</tt>. The problem is that if <tt>b</tt> is a recursive type, and
--   <tt>b'</tt> is <tt>b</tt>, then ghc will choke and blow the stack
--   (instead of computing a fixpoint).
--   
--   So, we would like to behave differently when <tt>b = b'</tt> and add
--   <tt>()</tt> instead of <tt><a>AllB</a> b c</tt> to break the
--   recursion. Our trick will be to use a type family to inspect
--   <tt><a>Rep</a> (b X)</tt>, for an arbitrary <tt>X</tt>, and
--   distinguish recursive usages from non-recursive ones, tagging them
--   with different types, so we can distinguish them in the instances.
type TagSelf0 (b :: k -> Type -> Type) = TagSelf0' Indexed b 1 RepN b X :: k -> Type
type family TagSelf0' (b :: kf -> Type) (repbf :: Type -> Type) :: Type -> Type

-- | We use the type-families to generically compute <tt><a>AllT</a> c
--   b</tt>. Intuitively, if <tt>t' f' x'</tt> occurs inside <tt>t f
--   x</tt>, then we should just add <tt><a>AllT</a> t' c</tt> to
--   <tt><a>AllT</a> t c</tt>. The problem is that if <tt>t</tt> is a
--   recursive type, and <tt>t'</tt> is <tt>t</tt>, then ghc will choke and
--   blow the stack (instead of computing a fixpoint).
--   
--   So, we would like to behave differently when <tt>t = t'</tt> and add
--   <tt>()</tt> instead of <tt><a>AllT</a> t c</tt> to break the
--   recursion. Our trick will be to use a type family to inspect
--   <tt><a>Rep</a> (t X Y)</tt>, for arbitrary <tt>X</tt> and <tt>Y</tt>
--   and distinguish recursive usages from non-recursive ones, tagging them
--   with different types, so we can distinguish them in the instances.
type TagSelf1 (b :: k -> Type -> kg -> Type) = TagSelf1' Indexed b 2 Zip Rep Indexed b X :: k -> Type 1 Y :: kg Rep b X :: k -> Type Y :: kg
type family TagSelf1' (b :: kf -> kg -> Type) (repbf :: Type -> Type) :: Type -> Type

-- | Default implementation of <a>bstrip</a> based on <a>Generic</a>.
gbcoverDefault :: CanDeriveBareB b => b Bare Identity -> b Covered Identity

-- | Default implementation of <a>bstrip</a> based on <a>Generic</a>.
gbstripDefault :: CanDeriveBareB b => b Covered Identity -> b Bare Identity
class GBare (n :: Nat) (repbi :: k -> Type) (repbb :: k -> Type)
gstrip :: forall (x :: k). GBare n repbi repbb => Proxy n -> repbi x -> repbb x
gcover :: forall (x :: k). GBare n repbi repbb => Proxy n -> repbb x -> repbi x

-- | All types that admit a generic <a>FunctorB</a> instance, and have all
--   their occurrences of <tt>f</tt> under a <a>Wear</a> admit a generic
--   <a>BareB</a> instance.
type CanDeriveBareB (b :: Type -> Type -> Type -> Type) = (GenericP 0 b Bare Identity, GenericP 0 b Covered Identity, GBare 0 RepP 0 b Covered Identity RepP 0 b Bare Identity)

-- | Representable types of kind <tt>*</tt>. This class is derivable in GHC
--   with the <tt>DeriveGeneric</tt> flag on.
--   
--   A <a>Generic</a> instance must satisfy the following laws:
--   
--   <pre>
--   <a>from</a> . <a>to</a> ≡ <a>id</a>
--   <a>to</a> . <a>from</a> ≡ <a>id</a>
--   </pre>
class Generic a where {
    
    -- | Generic representation type
    type Rep a :: Type -> Type;
}

-- | Convert from the datatype to its representation
from :: Generic a => a -> Rep a x

-- | Convert from the representation to the datatype
to :: Generic a => Rep a x -> a

-- | Representable types of kind <tt>* -&gt; *</tt> (or kind <tt>k -&gt;
--   *</tt>, when <tt>PolyKinds</tt> is enabled). This class is derivable
--   in GHC with the <tt>DeriveGeneric</tt> flag on.
--   
--   A <a>Generic1</a> instance must satisfy the following laws:
--   
--   <pre>
--   <a>from1</a> . <a>to1</a> ≡ <a>id</a>
--   <a>to1</a> . <a>from1</a> ≡ <a>id</a>
--   </pre>
class Generic1 (f :: k -> Type) where {
    
    -- | Generic representation type
    type Rep1 (f :: k -> Type) :: k -> Type;
}

-- | Convert from the datatype to its representation
from1 :: forall (a :: k). Generic1 f => f a -> Rep1 f a

-- | Convert from the representation to the datatype
to1 :: forall (a :: k). Generic1 f => Rep1 f a -> f a

-- | Class for datatypes that represent datatypes
class Datatype (d :: k)

-- | The name of the datatype (unqualified)
datatypeName :: forall k1 t (f :: k1 -> Type) (a :: k1). Datatype d => t d f a -> [Char]

-- | The fully-qualified name of the module where the type is declared
moduleName :: forall k1 t (f :: k1 -> Type) (a :: k1). Datatype d => t d f a -> [Char]

-- | The package name of the module where the type is declared
packageName :: forall k1 t (f :: k1 -> Type) (a :: k1). Datatype d => t d f a -> [Char]

-- | Marks if the datatype is actually a newtype
isNewtype :: forall k1 t (f :: k1 -> Type) (a :: k1). Datatype d => t d f a -> Bool

-- | Class for datatypes that represent data constructors
class Constructor (c :: k)

-- | The name of the constructor
conName :: forall k1 t (f :: k1 -> Type) (a :: k1). Constructor c => t c f a -> [Char]

-- | The fixity of the constructor
conFixity :: forall k1 t (f :: k1 -> Type) (a :: k1). Constructor c => t c f a -> Fixity

-- | Marks if this constructor is a record
conIsRecord :: forall k1 t (f :: k1 -> Type) (a :: k1). Constructor c => t c f a -> Bool

-- | Class for datatypes that represent records
class Selector (s :: k)

-- | The name of the selector
selName :: forall k1 t (f :: k1 -> Type) (a :: k1). Selector s => t s f a -> [Char]

-- | The selector's unpackedness annotation (if any)
selSourceUnpackedness :: forall k1 t (f :: k1 -> Type) (a :: k1). Selector s => t s f a -> SourceUnpackedness

-- | The selector's strictness annotation (if any)
selSourceStrictness :: forall k1 t (f :: k1 -> Type) (a :: k1). Selector s => t s f a -> SourceStrictness

-- | The strictness that the compiler inferred for the selector
selDecidedStrictness :: forall k1 t (f :: k1 -> Type) (a :: k1). Selector s => t s f a -> DecidedStrictness

-- | Void: used for datatypes without constructors
data V1 (p :: k)

-- | Unit: used for constructors without arguments
data U1 (p :: k)
U1 :: U1 (p :: k)

-- | Used for marking occurrences of the parameter
newtype Par1 p
Par1 :: p -> Par1 p
[unPar1] :: Par1 p -> p

-- | Recursive calls of kind <tt>* -&gt; *</tt> (or kind <tt>k -&gt;
--   *</tt>, when <tt>PolyKinds</tt> is enabled)
newtype Rec1 (f :: k -> Type) (p :: k)
Rec1 :: f p -> Rec1 (f :: k -> Type) (p :: k)
[unRec1] :: Rec1 (f :: k -> Type) (p :: k) -> f p

-- | Constants, additional parameters and recursion of kind <tt>*</tt>
newtype K1 i c (p :: k)
K1 :: c -> K1 i c (p :: k)
[unK1] :: K1 i c (p :: k) -> c

-- | Meta-information (constructor names, etc.)
newtype M1 i (c :: Meta) (f :: k -> Type) (p :: k)
M1 :: f p -> M1 i (c :: Meta) (f :: k -> Type) (p :: k)
[unM1] :: M1 i (c :: Meta) (f :: k -> Type) (p :: k) -> f p

-- | Sums: encode choice between constructors
data ( (f :: k -> Type) :+: (g :: k -> Type) ) (p :: k)
L1 :: f p -> (:+:) (f :: k -> Type) (g :: k -> Type) (p :: k)
R1 :: g p -> (:+:) (f :: k -> Type) (g :: k -> Type) (p :: k)
infixr 5 :+:

-- | Products: encode multiple arguments to constructors
data ( (f :: k -> Type) :*: (g :: k -> Type) ) (p :: k)
(:*:) :: f p -> g p -> (:*:) (f :: k -> Type) (g :: k -> Type) (p :: k)
infixr 6 :*:
infixr 6 :*:

-- | Composition of functors
newtype ( (f :: k2 -> Type) :.: (g :: k1 -> k2) ) (p :: k1)
Comp1 :: f (g p) -> (:.:) (f :: k2 -> Type) (g :: k1 -> k2) (p :: k1)
[unComp1] :: (:.:) (f :: k2 -> Type) (g :: k1 -> k2) (p :: k1) -> f (g p)
infixr 7 :.:

-- | Tag for K1: recursion (of kind <tt>Type</tt>)
data R

-- | Tag for M1: datatype
data D

-- | Tag for M1: constructor
data C

-- | Tag for M1: record selector
data S

-- | Type synonym for encoding recursion (of kind <tt>Type</tt>)
type Rec0 = K1 R :: Type -> k -> Type

-- | Type synonym for encoding meta-information for datatypes
type D1 = M1 D :: Meta -> k -> Type -> k -> Type

-- | Type synonym for encoding meta-information for constructors
type C1 = M1 C :: Meta -> k -> Type -> k -> Type

-- | Type synonym for encoding meta-information for record selectors
type S1 = M1 S :: Meta -> k -> Type -> k -> Type

-- | Generic representation type
type family Rep a :: Type -> Type

-- | Generic representation type
type family Rep1 (f :: k -> Type) :: k -> Type

-- | Constants of unlifted kinds
data family URec a (p :: k)

-- | Type synonym for <tt><a>URec</a> <a>Addr#</a></tt>
type UAddr = URec Ptr () :: k -> Type

-- | Type synonym for <tt><a>URec</a> <a>Char#</a></tt>
type UChar = URec Char :: k -> Type

-- | Type synonym for <tt><a>URec</a> <a>Double#</a></tt>
type UDouble = URec Double :: k -> Type

-- | Type synonym for <tt><a>URec</a> <a>Float#</a></tt>
type UFloat = URec Float :: k -> Type

-- | Type synonym for <tt><a>URec</a> <a>Int#</a></tt>
type UInt = URec Int :: k -> Type

-- | Type synonym for <tt><a>URec</a> <a>Word#</a></tt>
type UWord = URec Word :: k -> Type

-- | This variant of <a>Fixity</a> appears at the type level.
data FixityI
PrefixI :: FixityI
InfixI :: Associativity -> Nat -> FixityI

-- | Datatype to represent the associativity of a constructor
data Associativity
LeftAssociative :: Associativity
RightAssociative :: Associativity
NotAssociative :: Associativity

-- | The unpackedness of a field as the user wrote it in the source code.
--   For example, in the following data type:
--   
--   <pre>
--   data E = ExampleConstructor     Int
--              {-# NOUNPACK #-} Int
--              {-#   UNPACK #-} Int
--   </pre>
--   
--   The fields of <tt>ExampleConstructor</tt> have
--   <a>NoSourceUnpackedness</a>, <a>SourceNoUnpack</a>, and
--   <a>SourceUnpack</a>, respectively.
data SourceUnpackedness
NoSourceUnpackedness :: SourceUnpackedness
SourceNoUnpack :: SourceUnpackedness
SourceUnpack :: SourceUnpackedness

-- | The strictness of a field as the user wrote it in the source code. For
--   example, in the following data type:
--   
--   <pre>
--   data E = ExampleConstructor Int ~Int !Int
--   </pre>
--   
--   The fields of <tt>ExampleConstructor</tt> have
--   <a>NoSourceStrictness</a>, <a>SourceLazy</a>, and <a>SourceStrict</a>,
--   respectively.
data SourceStrictness
NoSourceStrictness :: SourceStrictness
SourceLazy :: SourceStrictness
SourceStrict :: SourceStrictness

-- | The strictness that GHC infers for a field during compilation. Whereas
--   there are nine different combinations of <a>SourceUnpackedness</a> and
--   <a>SourceStrictness</a>, the strictness that GHC decides will
--   ultimately be one of lazy, strict, or unpacked. What GHC decides is
--   affected both by what the user writes in the source code and by GHC
--   flags. As an example, consider this data type:
--   
--   <pre>
--   data E = ExampleConstructor {-# UNPACK #-} !Int !Int Int
--   </pre>
--   
--   <ul>
--   <li>If compiled without optimization or other language extensions,
--   then the fields of <tt>ExampleConstructor</tt> will have
--   <a>DecidedStrict</a>, <a>DecidedStrict</a>, and <a>DecidedLazy</a>,
--   respectively.</li>
--   <li>If compiled with <tt>-XStrictData</tt> enabled, then the fields
--   will have <a>DecidedStrict</a>, <a>DecidedStrict</a>, and
--   <a>DecidedStrict</a>, respectively.</li>
--   <li>If compiled with <tt>-O2</tt> enabled, then the fields will have
--   <a>DecidedUnpack</a>, <a>DecidedStrict</a>, and <a>DecidedLazy</a>,
--   respectively.</li>
--   </ul>
data DecidedStrictness
DecidedLazy :: DecidedStrictness
DecidedStrict :: DecidedStrictness
DecidedUnpack :: DecidedStrictness

-- | Datatype to represent metadata associated with a datatype
--   (<tt>MetaData</tt>), constructor (<tt>MetaCons</tt>), or field
--   selector (<tt>MetaSel</tt>).
--   
--   <ul>
--   <li>In <tt>MetaData n m p nt</tt>, <tt>n</tt> is the datatype's name,
--   <tt>m</tt> is the module in which the datatype is defined, <tt>p</tt>
--   is the package in which the datatype is defined, and <tt>nt</tt> is
--   <tt>'True</tt> if the datatype is a <tt>newtype</tt>.</li>
--   <li>In <tt>MetaCons n f s</tt>, <tt>n</tt> is the constructor's name,
--   <tt>f</tt> is its fixity, and <tt>s</tt> is <tt>'True</tt> if the
--   constructor contains record selectors.</li>
--   <li>In <tt>MetaSel mn su ss ds</tt>, if the field uses record syntax,
--   then <tt>mn</tt> is <a>Just</a> the record name. Otherwise,
--   <tt>mn</tt> is <a>Nothing</a>. <tt>su</tt> and <tt>ss</tt> are the
--   field's unpackedness and strictness annotations, and <tt>ds</tt> is
--   the strictness that GHC infers for the field.</li>
--   </ul>
data Meta
MetaData :: Symbol -> Symbol -> Symbol -> Bool -> Meta
MetaCons :: Symbol -> FixityI -> Bool -> Meta
MetaSel :: Maybe Symbol -> SourceUnpackedness -> SourceStrictness -> DecidedStrictness -> Meta

-- | Get the precedence of a fixity value.
prec :: Fixity -> Int

-- | A type whose instances are defined generically, using the
--   <a>Generic1</a> representation. <a>Generically1</a> is a higher-kinded
--   version of <a>Generically</a> that uses <a>Generic</a>.
--   
--   Generic instances can be derived for type constructors via
--   <tt><a>Generically1</a> F</tt> using <tt>-XDerivingVia</tt>.
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock (Functor, Generic1)
--   
--     deriving Applicative
--     via Generically1 V4
--   </pre>
--   
--   This corresponds to <a>Applicative</a> instances defined by pointwise
--   lifting:
--   
--   <pre>
--   instance Applicative V4 where
--     pure :: a -&gt; V4 a
--     pure a = V4 a a a a
--   
--     liftA2 :: (a -&gt; b -&gt; c) -&gt; (V4 a -&gt; V4 b -&gt; V4 c)
--     liftA2 (·) (V4 a1 b1 c1 d1) (V4 a2 b2 c2 d2) =
--       V4 (a1 · a2) (b1 · b2) (c1 · c2) (d1 · d2)
--   </pre>
--   
--   Historically this required modifying the type class to include generic
--   method definitions (<tt>-XDefaultSignatures</tt>) and deriving it with
--   the <tt>anyclass</tt> strategy (<tt>-XDeriveAnyClass</tt>). Having a
--   /via type/ like <a>Generically1</a> decouples the instance from the
--   type class.
newtype Generically1 (f :: k -> Type) (a :: k)
[Generically1] :: forall {k} (f :: k -> Type) (a :: k). f a -> Generically1 f a

-- | A datatype whose instances are defined generically, using the
--   <a>Generic</a> representation. <a>Generically1</a> is a higher-kinded
--   version of <a>Generically</a> that uses <a>Generic1</a>.
--   
--   Generic instances can be derived via <tt><a>Generically</a> A</tt>
--   using <tt>-XDerivingVia</tt>.
--   
--   <pre>
--   {-# LANGUAGE DeriveGeneric      #-}
--   {-# LANGUAGE DerivingStrategies #-}
--   {-# LANGUAGE DerivingVia        #-}
--   
--   import GHC.Generics (Generic)
--   
--   data V4 a = V4 a a a a
--     deriving stock Generic
--   
--     deriving (Semigroup, Monoid)
--     via Generically (V4 a)
--   </pre>
--   
--   This corresponds to <a>Semigroup</a> and <a>Monoid</a> instances
--   defined by pointwise lifting:
--   
--   <pre>
--   instance Semigroup a =&gt; Semigroup (V4 a) where
--     (&lt;&gt;) :: V4 a -&gt; V4 a -&gt; V4 a
--     V4 a1 b1 c1 d1 &lt;&gt; V4 a2 b2 c2 d2 =
--       V4 (a1 &lt;&gt; a2) (b1 &lt;&gt; b2) (c1 &lt;&gt; c2) (d1 &lt;&gt; d2)
--   
--   instance Monoid a =&gt; Monoid (V4 a) where
--     mempty :: V4 a
--     mempty = V4 mempty mempty mempty mempty
--   </pre>
--   
--   Historically this required modifying the type class to include generic
--   method definitions (<tt>-XDefaultSignatures</tt>) and deriving it with
--   the <tt>anyclass</tt> strategy (<tt>-XDeriveAnyClass</tt>). Having a
--   /via type/ like <a>Generically</a> decouples the instance from the
--   type class.
newtype Generically a
Generically :: a -> Generically a

-- | Datatype to represent the fixity of a constructor. An infix |
--   declaration directly corresponds to an application of <a>Infix</a>.
data Fixity
Prefix :: Fixity
Infix :: Associativity -> Int -> Fixity
class (Coercible Rep a RepN a, Generic a) => GenericN a where {
    type RepN a :: Type -> Type;
    type RepN a = Zip Rep Indexed a 0 Rep a;
}
toN :: GenericN a => RepN a x -> a
fromN :: GenericN a => a -> RepN a x
newtype Rec p a (x :: k)
Rec :: K1 R a x -> Rec p a (x :: k)
[unRec] :: Rec p a (x :: k) -> K1 R a x
data family Param (n :: Nat) (a :: k) :: k
type family Indexed (t :: k) (i :: Nat) :: k
type family FilterIndex (n :: Nat) (t :: k) :: k
type family Zip (a :: Type -> Type) (b :: Type -> Type) :: Type -> Type
class (Coercible Rep a RepP n a, Generic a) => GenericP (n :: Nat) a where {
    type RepP (n :: Nat) a :: Type -> Type;
    type RepP n :: Nat a = Zip Rep FilterIndex n Indexed a 0 Rep a;
}
toP :: GenericP n a => Proxy n -> RepP n a x -> a
fromP :: GenericP n a => Proxy n -> a -> RepP n a x
type family RepN a :: Type -> Type
type family RepP (n :: Nat) a :: Type -> Type
