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

-- | Contravariant functors
--   
--   Contravariant functors.
@package contravariant
@version 1.5.5

-- | This module supplies contravariant analogues to the Applicative
--   and Alternative classes.
module Data.Functor.Contravariant.Divisible

-- | A Divisible contravariant functor is the contravariant analogue
--   of Applicative.
--   
--   Continuing the intuition that Contravariant functors consume
--   input, a Divisible contravariant functor also has the ability
--   to be composed "beside" another contravariant functor.
--   
--   Serializers provide a good example of Divisible contravariant
--   functors. To begin let's start with the type of serializers for
--   specific types:
--   
--   
--   newtype Serializer a = Serializer { runSerializer :: a -> ByteString }
--   
--   
--   This is a contravariant functor:
--   
--   
--   instance Contravariant Serializer where
--     contramap f s = Serializer (runSerializer s . f)
--   
--   
--   That is, given a serializer for a (s :: Serializer
--   a), and a way to turn bs into as (a mapping
--   f :: b -> a), we have a serializer for b:
--   contramap f s :: Serializer b.
--   
--   Divisible gives us a way to combine two serializers that focus on
--   different parts of a structure. If we postulate the existance of two
--   primitive serializers - string :: Serializer String and
--   int :: Serializer Int, we would like to be able to combine
--   these into a serializer for pairs of Strings and
--   Ints. How can we do this? Simply run both serializers and
--   combine their output!
--   
--   
--   data StringAndInt = StringAndInt String Int
--   
--   stringAndInt :: Serializer StringAndInt
--   stringAndInt = Serializer $ \(StringAndInt s i) ->
--     let sBytes = runSerializer string s
--         iBytes = runSerializer int i
--     in sBytes <> iBytes
--   
--   
--   divide is a generalization by also taking a contramap
--   like function to split any a into a pair. This conveniently
--   allows you to target fields of a record, for instance, by extracting
--   the values under two fields and combining them into a tuple.
--   
--   To complete the example, here is how to write stringAndInt
--   using a Divisible instance:
--   
--   
--   instance Divisible Serializer where
--     conquer = Serializer (const mempty)
--   
--     divide toBC bSerializer cSerializer = Serializer $ \a ->
--       case toBC a of
--         (b, c) ->
--           let bBytes = runSerializer bSerializer b
--               cBytes = runSerializer cSerializer c
--           in bBytes <> cBytes
--   
--   stringAndInt :: Serializer StringAndInt
--   stringAndInt =
--     divide (\(StringAndInt s i) -> (s, i)) string int
--   
class Contravariant f => Divisible (f :: Type -> Type)
divide :: Divisible f => (a -> (b, c)) -> f b -> f c -> f a

-- | Conquer acts as an identity for combining Divisible functors.
conquer :: Divisible f => f a

-- | 
--   divided = divide id
--   
divided :: Divisible f => f a -> f b -> f (a, b)

-- | Redundant, but provided for symmetry.
--   
--   
--   conquered = conquer
--   
conquered :: Divisible f => f ()

-- | This is the divisible analogue of liftA. It gives a viable
--   default definition for contramap in terms of the members of
--   Divisible.
--   
--   
--   liftD f = divide ((,) () . f) conquer
--   
liftD :: Divisible f => (a -> b) -> f b -> f a

-- | A Decidable contravariant functor is the contravariant analogue
--   of Alternative.
--   
--   Noting the superclass constraint that f must also be
--   Divisible, a Decidable functor has the ability to "fan
--   out" input, under the intuition that contravariant functors consume
--   input.
--   
--   In the discussion for Divisible, an example was demonstrated
--   with Serializers, that turn as into
--   ByteStrings. Divisible allowed us to serialize the
--   product of multiple values by concatenation. By making our
--   Serializer also Decidable- we now have the ability
--   to serialize the sum of multiple values - for example different
--   constructors in an ADT.
--   
--   Consider serializing arbitrary identifiers that can be either
--   Strings or Ints:
--   
--   
--   data Identifier = StringId String | IntId Int
--   
--   
--   We know we have serializers for Strings and Ints,
--   but how do we combine them into a Serializer for
--   Identifier? Essentially, our Serializer needs to
--   scrutinise the incoming value and choose how to serialize it:
--   
--   
--   identifier :: Serializer Identifier
--   identifier = Serializer $ \identifier ->
--     case identifier of
--       StringId s -> runSerializer string s
--       IntId i -> runSerializer int i
--   
--   
--   It is exactly this notion of choice that Decidable encodes.
--   Hence if we add an instance of Decidable for
--   Serializer...
--   
--   
--   instance Decidable Serializer where
--     lose f = Serializer $ \a -> absurd (f a)
--     choose split l r = Serializer $ \a ->
--       either (runSerializer l) (runSerializer r) (split a)
--   
--   
--   Then our identifier Serializer is
--   
--   
--   identifier :: Serializer Identifier
--   identifier = choose toEither string int where
--     toEither (StringId s) = Left s
--     toEither (IntId i) = Right i
--   
class Divisible f => Decidable (f :: Type -> Type)

-- | Acts as identity to choose.
lose :: Decidable f => (a -> Void) -> f a
choose :: Decidable f => (a -> Either b c) -> f b -> f c -> f a

-- | 
--   chosen = choose id
--   
chosen :: Decidable f => f b -> f c -> f (Either b c)

-- | 
--   lost = lose id
--   
lost :: Decidable f => f Void
instance (Data.Functor.Contravariant.Divisible.Decidable f, Data.Functor.Contravariant.Divisible.Decidable g) => Data.Functor.Contravariant.Divisible.Decidable (f GHC.Internal.Generics.:*: g)
instance (GHC.Internal.Base.Applicative f, Data.Functor.Contravariant.Divisible.Decidable g) => Data.Functor.Contravariant.Divisible.Decidable (f GHC.Internal.Generics.:.: g)
instance Data.Functor.Contravariant.Divisible.Decidable f => Data.Functor.Contravariant.Divisible.Decidable (GHC.Internal.Data.Semigroup.Internal.Alt f)
instance Data.Functor.Contravariant.Divisible.Decidable f => Data.Functor.Contravariant.Divisible.Decidable (Control.Applicative.Backwards.Backwards f)
instance Data.Functor.Contravariant.Divisible.Decidable Data.Functor.Contravariant.Comparison
instance (GHC.Internal.Base.Applicative f, Data.Functor.Contravariant.Divisible.Decidable g) => Data.Functor.Contravariant.Divisible.Decidable (Data.Functor.Compose.Compose f g)
instance Data.Functor.Contravariant.Divisible.Decidable Data.Functor.Contravariant.Equivalence
instance Data.Functor.Contravariant.Divisible.Decidable f => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.Identity.IdentityT f)
instance Data.Functor.Contravariant.Divisible.Decidable f => Data.Functor.Contravariant.Divisible.Decidable (GHC.Internal.Generics.M1 i c f)
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.Maybe.MaybeT m)
instance GHC.Internal.Base.Monoid r => Data.Functor.Contravariant.Divisible.Decidable (Data.Functor.Contravariant.Op r)
instance Data.Functor.Contravariant.Divisible.Decidable Data.Functor.Contravariant.Predicate
instance (Data.Functor.Contravariant.Divisible.Decidable f, Data.Functor.Contravariant.Divisible.Decidable g) => Data.Functor.Contravariant.Divisible.Decidable (Data.Functor.Product.Product f g)
instance Data.Functor.Contravariant.Divisible.Decidable GHC.Internal.Data.Proxy.Proxy
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.Reader.ReaderT r m)
instance Data.Functor.Contravariant.Divisible.Decidable f => Data.Functor.Contravariant.Divisible.Decidable (GHC.Internal.Generics.Rec1 f)
instance Data.Functor.Contravariant.Divisible.Decidable f => Data.Functor.Contravariant.Divisible.Decidable (Data.Functor.Reverse.Reverse f)
instance Data.Functor.Contravariant.Divisible.Decidable Data.StateVar.SettableStateVar
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.State.Strict.StateT s m)
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.State.Lazy.StateT s m)
instance Data.Functor.Contravariant.Divisible.Decidable GHC.Internal.Generics.U1
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance Data.Functor.Contravariant.Divisible.Decidable m => Data.Functor.Contravariant.Divisible.Decidable (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (Data.Functor.Contravariant.Divisible.Divisible f, Data.Functor.Contravariant.Divisible.Divisible g) => Data.Functor.Contravariant.Divisible.Divisible (f GHC.Internal.Generics.:*: g)
instance (GHC.Internal.Base.Applicative f, Data.Functor.Contravariant.Divisible.Divisible g) => Data.Functor.Contravariant.Divisible.Divisible (f GHC.Internal.Generics.:.: g)
instance Data.Functor.Contravariant.Divisible.Divisible f => Data.Functor.Contravariant.Divisible.Divisible (GHC.Internal.Data.Semigroup.Internal.Alt f)
instance Data.Functor.Contravariant.Divisible.Divisible f => Data.Functor.Contravariant.Divisible.Divisible (Control.Applicative.Backwards.Backwards f)
instance Data.Functor.Contravariant.Divisible.Divisible Data.Functor.Contravariant.Comparison
instance (GHC.Internal.Base.Applicative f, Data.Functor.Contravariant.Divisible.Divisible g) => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Compose.Compose f g)
instance GHC.Internal.Base.Monoid m => Data.Functor.Contravariant.Divisible.Divisible (GHC.Internal.Data.Functor.Const.Const m)
instance GHC.Internal.Base.Monoid m => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Constant.Constant m)
instance Data.Functor.Contravariant.Divisible.Divisible Data.Functor.Contravariant.Equivalence
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.Except.ExceptT e m)
instance Data.Functor.Contravariant.Divisible.Divisible f => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.Identity.IdentityT f)
instance Data.Functor.Contravariant.Divisible.Divisible f => Data.Functor.Contravariant.Divisible.Divisible (GHC.Internal.Generics.M1 i c f)
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.Maybe.MaybeT m)
instance GHC.Internal.Base.Monoid r => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Contravariant.Op r)
instance Data.Functor.Contravariant.Divisible.Divisible Data.Functor.Contravariant.Predicate
instance (Data.Functor.Contravariant.Divisible.Divisible f, Data.Functor.Contravariant.Divisible.Divisible g) => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Product.Product f g)
instance Data.Functor.Contravariant.Divisible.Divisible GHC.Internal.Data.Proxy.Proxy
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.Reader.ReaderT r m)
instance Data.Functor.Contravariant.Divisible.Divisible f => Data.Functor.Contravariant.Divisible.Divisible (GHC.Internal.Generics.Rec1 f)
instance Data.Functor.Contravariant.Divisible.Divisible f => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Reverse.Reverse f)
instance Data.Functor.Contravariant.Divisible.Divisible Data.StateVar.SettableStateVar
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.State.Strict.StateT s m)
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.State.Lazy.StateT s m)
instance Data.Functor.Contravariant.Divisible.Divisible GHC.Internal.Generics.U1
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance Data.Functor.Contravariant.Divisible.Divisible m => Data.Functor.Contravariant.Divisible.Divisible (Control.Monad.Trans.Writer.Lazy.WriterT w m)

-- | Composition of contravariant functors.
module Data.Functor.Contravariant.Compose

-- | Composition of two contravariant functors
newtype Compose (f :: Type -> Type) (g :: Type -> Type) a
Compose :: f (g a) -> Compose (f :: Type -> Type) (g :: Type -> Type) a
[getCompose] :: Compose (f :: Type -> Type) (g :: Type -> Type) a -> f (g a)

-- | Composition of covariant and contravariant functors
newtype ComposeFC (f :: Type -> Type) (g :: Type -> Type) a
ComposeFC :: f (g a) -> ComposeFC (f :: Type -> Type) (g :: Type -> Type) a
[getComposeFC] :: ComposeFC (f :: Type -> Type) (g :: Type -> Type) a -> f (g a)

-- | Composition of contravariant and covariant functors
newtype ComposeCF (f :: Type -> Type) (g :: Type -> Type) a
ComposeCF :: f (g a) -> ComposeCF (f :: Type -> Type) (g :: Type -> Type) a
[getComposeCF] :: ComposeCF (f :: Type -> Type) (g :: Type -> Type) a -> f (g a)
instance (Data.Functor.Contravariant.Contravariant f, GHC.Internal.Base.Functor g) => Data.Functor.Contravariant.Contravariant (Data.Functor.Contravariant.Compose.ComposeCF f g)
instance (GHC.Internal.Base.Functor f, Data.Functor.Contravariant.Contravariant g) => Data.Functor.Contravariant.Contravariant (Data.Functor.Contravariant.Compose.ComposeFC f g)
instance (GHC.Internal.Base.Applicative f, Data.Functor.Contravariant.Divisible.Decidable g) => Data.Functor.Contravariant.Divisible.Decidable (Data.Functor.Contravariant.Compose.ComposeFC f g)
instance (Data.Functor.Contravariant.Divisible.Divisible f, GHC.Internal.Base.Applicative g) => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Contravariant.Compose.ComposeCF f g)
instance (GHC.Internal.Base.Applicative f, Data.Functor.Contravariant.Divisible.Divisible g) => Data.Functor.Contravariant.Divisible.Divisible (Data.Functor.Contravariant.Compose.ComposeFC f g)
instance (Data.Functor.Contravariant.Contravariant f, Data.Functor.Contravariant.Contravariant g) => GHC.Internal.Base.Functor (Data.Functor.Contravariant.Compose.Compose f g)
instance (GHC.Internal.Base.Functor f, GHC.Internal.Base.Functor g) => GHC.Internal.Base.Functor (Data.Functor.Contravariant.Compose.ComposeCF f g)
instance (GHC.Internal.Base.Functor f, GHC.Internal.Base.Functor g) => GHC.Internal.Base.Functor (Data.Functor.Contravariant.Compose.ComposeFC f g)

module Data.Functor.Contravariant.Generic

-- | This provides machinery for deconstructing an arbitrary Generic
--   instance using a Decidable Contravariant functor.
--   
--   Examples:
--   
--   
--   gcompare :: Deciding Ord a => a -> a -> Ordering
--   gcompare = getComparison $ deciding (Proxy :: Proxy Ord) (Comparison compare)
--   
--   
--   
--   geq :: Deciding Eq a => a -> a -> Bool
--   geq = getEquivalence $ deciding (Proxy :: Proxy Eq) (Equivalence (==))
--   
class (Generic a, GDeciding q Rep' a) => Deciding (q :: Type -> Constraint) a
deciding :: (Deciding q a, Decidable f) => p q -> (forall b. q b => f b) -> f a

-- | This provides machinery for deconstructing an arbitrary
--   Generic1 instance using a Decidable Contravariant
--   functor.
--   
--   Examples:
--   
--   
--   gcompare1 :: Deciding1 Ord f => (a -> a -> Ordering) -> f a -> f a -> Ordering
--   gcompare1 f = getComparison $ deciding1 (Proxy :: Proxy Ord) (Comparison compare) (Comparison f)
--   
--   
--   
--   geq1 :: Deciding1 Eq f => (a -> a -> Bool) -> f a -> f a -> Bool
--   geq1 f = getEquivalence $ deciding1 (Proxy :: Proxy Eq) (Equivalence (==)) (Equivalence f)
--   
class (Generic1 t, GDeciding1 q Rep1' t) => Deciding1 (q :: Type -> Constraint) (t :: Type -> Type)
deciding1 :: (Deciding1 q t, Decidable f) => p q -> (forall b. q b => f b) -> f a -> f (t a)
instance (GHC.Internal.Generics.Generic1 t, Data.Functor.Contravariant.Generic.GDeciding1 q (Data.Functor.Contravariant.Generic.Rep1' t), Data.Functor.Contravariant.Generic.GG (GHC.Internal.Generics.Rep1 t)) => Data.Functor.Contravariant.Generic.Deciding1 q t
instance (GHC.Internal.Generics.Generic a, Data.Functor.Contravariant.Generic.GG (GHC.Internal.Generics.Rep a), Data.Functor.Contravariant.Generic.GDeciding q (Data.Functor.Contravariant.Generic.Rep' a)) => Data.Functor.Contravariant.Generic.Deciding q a
instance (Data.Functor.Contravariant.Generic.GDeciding1 q f, Data.Functor.Contravariant.Generic.GDeciding1 q g) => Data.Functor.Contravariant.Generic.GDeciding1 q (f Data.Functor.Contravariant.Generic.::*: g)
instance (Data.Functor.Contravariant.Generic.GDeciding1 q f, Data.Functor.Contravariant.Generic.GDeciding1 q g) => Data.Functor.Contravariant.Generic.GDeciding1 q (f Data.Functor.Contravariant.Generic.::+: g)
instance q p => Data.Functor.Contravariant.Generic.GDeciding1 q (GHC.Internal.Generics.K1 i p)
instance Data.Functor.Contravariant.Generic.GDeciding1 q f => Data.Functor.Contravariant.Generic.GDeciding1 q (GHC.Internal.Generics.M1 i c f)
instance Data.Functor.Contravariant.Generic.GDeciding1 q GHC.Internal.Generics.Par1
instance Data.Functor.Contravariant.Generic.Deciding1 q f => Data.Functor.Contravariant.Generic.GDeciding1 q (GHC.Internal.Generics.Rec1 f)
instance Data.Functor.Contravariant.Generic.GDeciding1 q GHC.Internal.Generics.U1
instance Data.Functor.Contravariant.Generic.GDeciding1 q GHC.Internal.Generics.V1
instance forall k (q :: * -> GHC.Types.Constraint) (f :: k -> *) (g :: k -> *). (Data.Functor.Contravariant.Generic.GDeciding q f, Data.Functor.Contravariant.Generic.GDeciding q g) => Data.Functor.Contravariant.Generic.GDeciding q (f Data.Functor.Contravariant.Generic.::*: g)
instance forall k (q :: * -> GHC.Types.Constraint) (f :: k -> *) (g :: k -> *). (Data.Functor.Contravariant.Generic.GDeciding q f, Data.Functor.Contravariant.Generic.GDeciding q g) => Data.Functor.Contravariant.Generic.GDeciding q (f Data.Functor.Contravariant.Generic.::+: g)
instance q p => Data.Functor.Contravariant.Generic.GDeciding q (GHC.Internal.Generics.K1 i p)
instance forall k (q :: * -> GHC.Types.Constraint) (f :: k -> *) i (c :: GHC.Internal.Generics.Meta). Data.Functor.Contravariant.Generic.GDeciding q f => Data.Functor.Contravariant.Generic.GDeciding q (GHC.Internal.Generics.M1 i c f)
instance Data.Functor.Contravariant.Generic.GDeciding q GHC.Internal.Generics.U1
instance Data.Functor.Contravariant.Generic.GDeciding q GHC.Internal.Generics.V1
instance (Data.Functor.Contravariant.Generic.GG f, Data.Functor.Contravariant.Generic.GG g) => Data.Functor.Contravariant.Generic.GG (f GHC.Internal.Generics.:*: g)
instance (Data.Functor.Contravariant.Generic.GG f, Data.Functor.Contravariant.Generic.GG g) => Data.Functor.Contravariant.Generic.GG (f GHC.Internal.Generics.:+: g)
instance Data.Functor.Contravariant.Generic.GG (GHC.Internal.Generics.K1 i c)
instance Data.Functor.Contravariant.Generic.GG f => Data.Functor.Contravariant.Generic.GG (GHC.Internal.Generics.M1 i c f)
instance Data.Functor.Contravariant.Generic.GG GHC.Internal.Generics.Par1
instance Data.Functor.Contravariant.Generic.GG (GHC.Internal.Generics.Rec1 f)
instance Data.Functor.Contravariant.Generic.GG GHC.Internal.Generics.U1
instance Data.Functor.Contravariant.Generic.GG GHC.Internal.Generics.V1
