-- 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 0.1.3.0 module Data.Barbie.Internal.Functor -- | Barbie-types that can be mapped over. Instances of FunctorB -- should satisfy the following laws: -- --
--   bmap id = id
--   bmap f . bmap g = bmap (f . g)
--   
-- -- There is a default bmap implementation for Generic -- types, so instances can derived automatically. class FunctorB b bmap :: FunctorB b => (forall a. f a -> g a) -> b f -> b g bmap :: (FunctorB b, CanDeriveGenericInstance b) => (forall a. f a -> g a) -> b f -> b g class GFunctorB b -- | Default implementation of bmap based on Generic. gbmapDefault :: CanDeriveGenericInstance b => (forall a. f a -> g a) -> b f -> b g -- | Intuivively, the requirements to have FunctorB B -- derived are: -- -- type CanDeriveGenericInstance b = (Generic (b (Target F)), Generic (b (Target G)), GFunctorB (Rep (b (Target F))), Rep (b (Target G)) ~ Repl (Target F) (Target G) (Rep (b (Target F)))) instance Data.Barbie.Internal.Functor.FunctorB b => Data.Barbie.Internal.Functor.GFunctorB (GHC.Generics.K1 GHC.Generics.R (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F))) instance (GHC.Base.Functor h, Data.Barbie.Internal.Functor.FunctorB b, Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.G) (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) ~ GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.G)))) => Data.Barbie.Internal.Functor.GFunctorB (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) instance Data.Barbie.Internal.Functor.GFunctorB x => Data.Barbie.Internal.Functor.GFunctorB (GHC.Generics.M1 i c x) instance Data.Barbie.Internal.Functor.GFunctorB GHC.Generics.V1 instance Data.Barbie.Internal.Functor.GFunctorB GHC.Generics.U1 instance (Data.Barbie.Internal.Functor.GFunctorB l, Data.Barbie.Internal.Functor.GFunctorB r) => Data.Barbie.Internal.Functor.GFunctorB (l GHC.Generics.:*: r) instance (Data.Barbie.Internal.Functor.GFunctorB l, Data.Barbie.Internal.Functor.GFunctorB r) => Data.Barbie.Internal.Functor.GFunctorB (l GHC.Generics.:+: r) instance Data.Barbie.Internal.Functor.GFunctorB (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.F) a)) instance Data.Barbie.Internal.Functor.GFunctorB (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F a)) instance (GHC.Generics.K1 i c ~ Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.G) (GHC.Generics.K1 i c)) => Data.Barbie.Internal.Functor.GFunctorB (GHC.Generics.K1 i c) module Data.Barbie.Internal.Traversable -- | Barbie-types that can be traversed from left to right. Instances -- should satisfy the following laws: -- --
--    t . btraverse f = btraverse (t . f)  -- naturality
--   btraverse Identity = Identity         -- identity
--   btraverse (Compose . fmap g . f) = Compose . fmap (btraverse g) . btraverse f -- composition
--   
-- -- There is a default btraverse implementation for Generic -- types, so instances can derived automatically. class FunctorB b => TraversableB b btraverse :: (TraversableB b, Applicative t) => (forall a. f a -> t (g a)) -> b f -> t (b g) btraverse :: (TraversableB b, Applicative t, CanDeriveGenericInstance b) => (forall a. f a -> t (g a)) -> b f -> t (b g) -- | Evaluate each action in the structure from left to right, and collect -- the results. bsequence :: (Applicative f, TraversableB b) => b (Compose f g) -> f (b g) -- | Intuivively, the requirements to have TraversableB B -- derived are: -- -- type CanDeriveGenericInstance b = (Generic (b (Target F)), Generic (b (Target G)), GTraversableB (Rep (b (Target F))), Rep (b (Target G)) ~ Repl (Target F) (Target G) (Rep (b (Target F)))) class GTraversableB b -- | Default implementation of btraverse based on Generic. gbtraverseDefault :: (Applicative t, CanDeriveGenericInstance b) => (forall a. f a -> t (g a)) -> b f -> t (b g) instance Data.Barbie.Internal.Traversable.TraversableB b => Data.Barbie.Internal.Traversable.GTraversableB (GHC.Generics.K1 GHC.Generics.R (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F))) instance (Data.Traversable.Traversable h, Data.Barbie.Internal.Traversable.TraversableB b, Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.G) (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) ~ GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.G)))) => Data.Barbie.Internal.Traversable.GTraversableB (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) instance Data.Barbie.Internal.Traversable.GTraversableB x => Data.Barbie.Internal.Traversable.GTraversableB (GHC.Generics.M1 i c x) instance Data.Barbie.Internal.Traversable.GTraversableB GHC.Generics.V1 instance Data.Barbie.Internal.Traversable.GTraversableB GHC.Generics.U1 instance (Data.Barbie.Internal.Traversable.GTraversableB l, Data.Barbie.Internal.Traversable.GTraversableB r) => Data.Barbie.Internal.Traversable.GTraversableB (l GHC.Generics.:*: r) instance (Data.Barbie.Internal.Traversable.GTraversableB l, Data.Barbie.Internal.Traversable.GTraversableB r) => Data.Barbie.Internal.Traversable.GTraversableB (l GHC.Generics.:+: r) instance Data.Barbie.Internal.Traversable.GTraversableB (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.F) a)) instance Data.Barbie.Internal.Traversable.GTraversableB (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F a)) instance (GHC.Generics.K1 i c ~ Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.G) (GHC.Generics.K1 i c)) => Data.Barbie.Internal.Traversable.GTraversableB (GHC.Generics.K1 i c) module Data.Barbie.Internal.Constraints -- | Instances of this class provide means to talk about constraints, both -- at compile-time, using ConstraintsOf and at run-time, in the -- form of class instance dictionaries, via adjProof. -- -- A manual definition would look like this: -- --
--   data T f = A (f Int) (f String) | B (f Bool) (f Int)
--   
--   instance ConstraintsB T where
--     type ConstraintsOf c f T
--       = (c (f Int), c (f String), c (f Bool))
--   
--     adjProof t = case t of
--       A x y -> A (Pair (packDict x) (packDict y))
--       B z w -> B (Pair (packDict z) (packDict w))
--   
-- -- There is a default implementation of ConstraintsOf for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic T
--   instance ConstraintsB T
--   
class FunctorB b => ConstraintsB b where { type family ConstraintsOf (c :: * -> Constraint) (f :: * -> *) b :: Constraint; type ConstraintsOf c f b = GConstraintsOf c f (RecRep (b (Target F))); } -- | Adjoint a proof-of-instance to a barbie-type. adjProof :: forall c f. (ConstraintsB b, ConstraintsOf c f b) => b f -> b (Product (DictOf c f) f) -- | Adjoint a proof-of-instance to a barbie-type. adjProof :: forall c f. (ConstraintsB b, CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b f -> b (Product (DictOf c f) f) -- | Intuivively, the requirements to have ConstraintsB B -- derived are: -- -- type CanDeriveGenericInstance b = (Generic (b (Target F)), Generic (b (Target PxF)), GAdjProof (ClassifyBarbie b) b (RecRep (b (Target F))), Rep (b (Target PxF)) ~ Repl' (Target F) (Target PxF) (RecRep (b (Target F)))) type ConstraintsOfMatchesGenericDeriv c f b = (ConstraintsOf c f b ~ GConstraintsOf c f (RecRep (b (Target F))), ConstraintsOf c f b ~ ConstraintByType (ClassifyBarbie b) c f (RecRep (b (Target F)))) type GConstraintsOf c f r = ConstraintByType (GClassifyBarbie r) c f r class GAdjProof (bt :: BarbieType) b rep -- | Default implementation of adjProof based on Generic. gadjProofDefault :: forall b c f. (CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b f -> b (Product (DictOf c f) f) instance Data.Barbie.Internal.Constraints.GAdjProof bt b x => Data.Barbie.Internal.Constraints.GAdjProof bt b (GHC.Generics.M1 _i _c x) instance Data.Barbie.Internal.Constraints.GAdjProof bt b GHC.Generics.V1 instance Data.Barbie.Internal.Constraints.GAdjProof bt b GHC.Generics.U1 instance (Data.Barbie.Internal.Constraints.GAdjProof bt b l, Data.Barbie.Internal.Constraints.GAdjProof bt b r) => Data.Barbie.Internal.Constraints.GAdjProof bt b (l GHC.Generics.:*: r) instance (Data.Barbie.Internal.Constraints.GAdjProof bt b l, Data.Barbie.Internal.Constraints.GAdjProof bt b r) => Data.Barbie.Internal.Constraints.GAdjProof bt b (l GHC.Generics.:+: r) instance Data.Barbie.Internal.Constraints.GAdjProof 'Data.Barbie.Internal.Classification.WearBarbie b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.NonRec (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.F) a))) instance Data.Barbie.Internal.Constraints.GAdjProof 'Data.Barbie.Internal.Classification.NonWearBarbie b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.NonRec (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F a))) instance (Data.Barbie.Internal.Constraints.CanDeriveGenericInstance b, bt ~ Data.Barbie.Internal.Classification.ClassifyBarbie b) => Data.Barbie.Internal.Constraints.GAdjProof bt b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.RecUsage (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) instance Data.Barbie.Internal.Constraints.ConstraintsB b' => Data.Barbie.Internal.Constraints.GAdjProof bt b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.NonRec (b' (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) instance (GHC.Generics.K1 i a ~ Data.Barbie.Internal.Generics.Repl' (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.PxF) (GHC.Generics.K1 i (Data.Barbie.Internal.Generics.NonRec a))) => Data.Barbie.Internal.Constraints.GAdjProof bt b (GHC.Generics.K1 i (Data.Barbie.Internal.Generics.NonRec a)) module Data.Barbie.Internal.Bare -- | The Wear type-function allows one to define a Barbie-type as -- --
--   data B f
--     = B { f1 :: Wear f Int
--         , f2 :: Wear f Bool
--         }
--   
-- -- This way, one can use Bare as a phantom that denotes no functor -- around the typw: -- --
--   B { f1 :: 5, f2 = True } :: B Bare
--   
-- | Bare is the only type such that Wear Bare a ~ -- a'. data Bare a -- | Class of Barbie-types defined using Wear and can therefore have -- Bare versions. Must satisfy: -- --
--   bcover . bstrip = id
--   bstrip . bcover = id
--   
class FunctorB b => BareB b bstrip :: BareB b => b Identity -> b Bare bcover :: BareB b => b Bare -> b Identity bstrip :: (BareB b, CanDeriveGenericInstance b) => b Identity -> b Bare bcover :: (BareB b, CanDeriveGenericInstance' b) => b Bare -> b Identity -- | Generalization of bstrip to arbitrary functors bstripFrom :: BareB b => (forall a. f a -> a) -> b f -> b Bare -- | Generalization of bcover to arbitrary functors bcoverWith :: BareB b => (forall a. a -> f a) -> b Bare -> b f class Gbstrip rep gbstrip :: Gbstrip rep => rep x -> Repl (Target I) (Target B) rep x -- | Default implementatio of bstrip based on Generic. gbstripDefault :: CanDeriveGenericInstance b => b Identity -> b Bare -- | Default implementatio of bstrip based on Generic. gbcoverDefault :: CanDeriveGenericInstance' b => b Bare -> b Identity -- | All types that admit a generic FunctorB' instance, and have all their -- occurrences of f under a Wear admit a generic -- BareB instance. type CanDeriveGenericInstance b = (Generic (b (Target I)), Generic (b (Target B)), Gbstrip (Rep (b (Target I))), Rep (b (Target B)) ~ Repl (Target I) (Target B) (Rep (b (Target I)))) type CanDeriveGenericInstance' b = (Generic (b (Target I)), Generic (b (Target B)), Gbcover (Rep (b (Target B))), Rep (b (Target I)) ~ Repl (Target B) (Target I) (Rep (b (Target B)))) instance Data.Barbie.Internal.Bare.BareB b => Data.Barbie.Internal.Bare.Gbstrip (GHC.Generics.K1 GHC.Generics.R (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I))) instance (GHC.Base.Functor h, Data.Barbie.Internal.Bare.BareB b, Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B) (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I)))) ~ GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B)))) => Data.Barbie.Internal.Bare.Gbstrip (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I)))) instance Data.Barbie.Internal.Bare.BareB b => Data.Barbie.Internal.Bare.Gbcover (GHC.Generics.K1 GHC.Generics.R (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B))) instance (GHC.Base.Functor h, Data.Barbie.Internal.Bare.BareB b, Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I) (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B)))) ~ GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I)))) => Data.Barbie.Internal.Bare.Gbcover (GHC.Generics.K1 GHC.Generics.R (h (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B)))) instance Data.Barbie.Internal.Bare.Gbcover x => Data.Barbie.Internal.Bare.Gbcover (GHC.Generics.M1 i c x) instance Data.Barbie.Internal.Bare.Gbcover GHC.Generics.V1 instance Data.Barbie.Internal.Bare.Gbcover GHC.Generics.U1 instance (Data.Barbie.Internal.Bare.Gbcover l, Data.Barbie.Internal.Bare.Gbcover r) => Data.Barbie.Internal.Bare.Gbcover (l GHC.Generics.:*: r) instance (Data.Barbie.Internal.Bare.Gbcover l, Data.Barbie.Internal.Bare.Gbcover r) => Data.Barbie.Internal.Bare.Gbcover (l GHC.Generics.:+: r) instance Data.Barbie.Internal.Bare.Gbcover (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.B) a)) instance (GHC.Generics.K1 i c ~ Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I) (GHC.Generics.K1 i c)) => Data.Barbie.Internal.Bare.Gbcover (GHC.Generics.K1 i c) instance Data.Barbie.Internal.Bare.Gbstrip x => Data.Barbie.Internal.Bare.Gbstrip (GHC.Generics.M1 i c x) instance Data.Barbie.Internal.Bare.Gbstrip GHC.Generics.V1 instance Data.Barbie.Internal.Bare.Gbstrip GHC.Generics.U1 instance (Data.Barbie.Internal.Bare.Gbstrip l, Data.Barbie.Internal.Bare.Gbstrip r) => Data.Barbie.Internal.Bare.Gbstrip (l GHC.Generics.:*: r) instance (Data.Barbie.Internal.Bare.Gbstrip l, Data.Barbie.Internal.Bare.Gbstrip r) => Data.Barbie.Internal.Bare.Gbstrip (l GHC.Generics.:+: r) instance Data.Barbie.Internal.Bare.Gbstrip (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.I) a)) instance (GHC.Generics.K1 i c ~ Data.Barbie.Internal.Generics.Repl (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.I) (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.B) (GHC.Generics.K1 i c)) => Data.Barbie.Internal.Bare.Gbstrip (GHC.Generics.K1 i c) -- | Generalize the standard two-functor Product to the product of -- n-functors. Intuitively, this means: -- --
--   Product f g a ~~ (f a, g a)
--   
--   Prod '[]        a ~~  Const () a
--   Prod '[f]       a ~~ (f a)
--   Prod '[f, g]    a ~~ (f a, g a)
--   Prod '[f, g, h] a ~~ (f a, g a, h a)
--       ⋮
--   
module Data.Functor.Prod -- | Product of n functors. data Prod :: [* -> *] -> * -> * [Unit] :: Prod '[] a [Cons] :: (f a) -> Prod fs a -> Prod (f : fs) a -- | The unit of the product. zeroTuple :: Prod '[] a -- | Lift a functor to a 1-tuple. oneTuple :: f a -> Prod '[f] a -- | Conversion from a standard Product fromProduct :: Product f g a -> Prod '[f, g] a -- | Conversion to a standard Product toProduct :: Prod '[f, g] a -> Product f g a -- | Flat product of products. prod :: Prod ls a -> Prod rs a -> Prod (ls ++ rs) a -- | Like uncurry but using Prod instead of pairs. Can be -- thought of as a family of functions: -- --
--   uncurryn :: r a -> Prod '[] a
--   uncurryn :: (f a -> r a) -> Prod '[f] a
--   uncurryn :: (f a -> g a -> r a) -> Prod '[f, g] a
--   uncurryn :: (f a -> g a -> h a -> r a) -> Prod '[f, g, h] a
--           ⋮
--   
uncurryn :: Curried (Prod fs a -> r a) -> Prod fs a -> r a -- | Type-level, poly-kinded, list-concatenation. -- | Prod '[f, g, h] a -> r is the type of the uncurried -- form of a function f a -> g a -> h a -> r. -- Curried moves from the former to the later. E.g. -- --
--   Curried (Prod '[]  a    -> r) = r a
--   Curried (Prod '[f] a    -> r) = f a -> r a
--   Curried (Prod '[f, g] a -> r) = f a -> g a -> r a
--   
instance GHC.Base.Functor (Data.Functor.Prod.Prod '[]) instance (GHC.Base.Functor f, GHC.Base.Functor (Data.Functor.Prod.Prod fs)) => GHC.Base.Functor (Data.Functor.Prod.Prod (f : fs)) instance GHC.Base.Applicative (Data.Functor.Prod.Prod '[]) instance (GHC.Base.Applicative f, GHC.Base.Applicative (Data.Functor.Prod.Prod fs)) => GHC.Base.Applicative (Data.Functor.Prod.Prod (f : fs)) instance GHC.Base.Alternative (Data.Functor.Prod.Prod '[]) instance (GHC.Base.Alternative f, GHC.Base.Alternative (Data.Functor.Prod.Prod fs)) => GHC.Base.Alternative (Data.Functor.Prod.Prod (f : fs)) instance Data.Foldable.Foldable (Data.Functor.Prod.Prod '[]) instance (Data.Foldable.Foldable f, Data.Foldable.Foldable (Data.Functor.Prod.Prod fs)) => Data.Foldable.Foldable (Data.Functor.Prod.Prod (f : fs)) instance Data.Traversable.Traversable (Data.Functor.Prod.Prod '[]) instance (Data.Traversable.Traversable f, Data.Traversable.Traversable (Data.Functor.Prod.Prod fs)) => Data.Traversable.Traversable (Data.Functor.Prod.Prod (f : fs)) instance Data.Functor.Classes.Eq1 (Data.Functor.Prod.Prod '[]) instance (Data.Functor.Classes.Eq1 f, Data.Functor.Classes.Eq1 (Data.Functor.Prod.Prod fs)) => Data.Functor.Classes.Eq1 (Data.Functor.Prod.Prod (f : fs)) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Functor.Prod.Prod '[] a) instance (Data.Functor.Classes.Eq1 f, GHC.Classes.Eq a, Data.Functor.Classes.Eq1 (Data.Functor.Prod.Prod fs)) => GHC.Classes.Eq (Data.Functor.Prod.Prod (f : fs) a) instance Data.Functor.Classes.Ord1 (Data.Functor.Prod.Prod '[]) instance (Data.Functor.Classes.Ord1 f, Data.Functor.Classes.Ord1 (Data.Functor.Prod.Prod fs)) => Data.Functor.Classes.Ord1 (Data.Functor.Prod.Prod (f : fs)) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Functor.Prod.Prod '[] a) instance (Data.Functor.Classes.Ord1 f, GHC.Classes.Ord a, Data.Functor.Classes.Ord1 (Data.Functor.Prod.Prod fs)) => GHC.Classes.Ord (Data.Functor.Prod.Prod (f : fs) a) instance Data.Functor.Classes.Show1 (Data.Functor.Prod.Prod '[]) instance (Data.Functor.Classes.Show1 f, Data.Functor.Classes.Show1 (Data.Functor.Prod.Prod fs)) => Data.Functor.Classes.Show1 (Data.Functor.Prod.Prod (f : fs)) instance GHC.Show.Show a => GHC.Show.Show (Data.Functor.Prod.Prod '[] a) instance (Data.Functor.Classes.Show1 f, GHC.Show.Show a, Data.Functor.Classes.Show1 (Data.Functor.Prod.Prod fs)) => GHC.Show.Show (Data.Functor.Prod.Prod (f : fs) a) module Data.Barbie.Internal.Product -- | Barbie-types that can form products, subject to the laws: -- --
--   bmap (Pair a _) . uncurry . bprod = fst
--   bmap (Pair _ b) . uncurry . bprod = snd
--   
-- -- Notice that because of the laws, having an internal product structure -- is not enough to have a lawful instance. E.g. -- --
--   data Ok  f = Ok {o1 :: f String, o2 :: f Int}        -- has an instance
--   data Bad f = Bad{b1 :: f String, hiddenFromArg: Int} -- no lawful instance
--   
-- -- Intuitively, the laws for this class require that b hides no -- structure from its argument f. Because of this, any x :: -- forall a . f a determines a unique value of b f, -- witnessed by the buniq method. Formally: -- --
--   const (buniq x) = bmap (const x)
--   
-- -- There is a default implementation of bprod and buniq for -- Generic types, so instances can derived automatically. class FunctorB b => ProductB b bprod :: ProductB b => b f -> b g -> b (Product f g) buniq :: ProductB b => (forall a. f a) -> b f bprod :: (ProductB b, CanDeriveGenericInstance b) => b f -> b g -> b (Product f g) buniq :: (ProductB b, CanDeriveGenericInstance' b) => (forall a. f a) -> b f -- | An alias of bprod, since this is like a zip for -- Barbie-types. bzip :: ProductB b => b f -> b g -> b (Product f g) -- | An equivalent of unzip for Barbie-types. bunzip :: ProductB b => b (Product f g) -> (b f, b g) -- | An equivalent of zipWith for Barbie-types. bzipWith :: ProductB b => (forall a. f a -> g a -> h a) -> b f -> b g -> b h -- | An equivalent of zipWith3 for Barbie-types. bzipWith3 :: ProductB b => (forall a. f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i -- | An equivalent of zipWith4 for Barbie-types. bzipWith4 :: ProductB b => (forall a. f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j -- | Like bprod, but returns a binary Prod, instead of -- Product, which composes better. -- -- See /*/ for usage. (/*/) :: ProductB b => b f -> b g -> b (Prod '[f, g]) infixr 4 /*/ -- | Similar to /*/ but one of the sides is already a 'Prod fs'. -- -- Note that /*, /*/ and uncurryn are meant to be -- used together: /* and /*/ combine b f1, b f2...b -- fn into a single product that can then be consumed by using -- uncurryn on an n-ary function. E.g. -- --
--   f :: f a -> g a -> h a -> i a
--   
--   bmap (uncurryn f) (bf /* bg /*/ bh)
--   
(/*) :: ProductB b => b f -> b (Prod fs) -> b (Prod (f : fs)) infixr 4 /* -- | The requirements to to derive ProductB (B f) are more -- strict than those for FunctorB or TraversableB. -- Intuitively, we need: -- -- type CanDeriveGenericInstance b = (Generic (b (Target F)), Generic (b (Target G)), Generic (b (Target FxG)), GProductB (Rep (b (Target F))), Rep (b (Target G)) ~ Repl (Target F) (Target G) (Rep (b (Target F))), Rep (b (Target FxG)) ~ Repl (Target F) (Target FxG) (Rep (b (Target F)))) type CanDeriveGenericInstance' b = (Generic (b (Target F)), GProductB (Rep (b (Target F)))) class GProductB b -- | Default implementation of bprod based on Generic. gbprodDefault :: CanDeriveGenericInstance b => b f -> b g -> b (Product f g) gbuniqDefault :: CanDeriveGenericInstance' b => (forall a. f a) -> b f instance Data.Barbie.Internal.Product.ProductB b => Data.Barbie.Internal.Product.GProductB (GHC.Generics.K1 GHC.Generics.R (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F))) instance Data.Barbie.Internal.Product.GProductB x => Data.Barbie.Internal.Product.GProductB (GHC.Generics.M1 i c x) instance Data.Barbie.Internal.Product.GProductB GHC.Generics.U1 instance (Data.Barbie.Internal.Product.GProductB l, Data.Barbie.Internal.Product.GProductB r) => Data.Barbie.Internal.Product.GProductB (l GHC.Generics.:*: r) instance Data.Barbie.Internal.Product.GProductB (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.F) a)) instance Data.Barbie.Internal.Product.GProductB (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F a)) module Data.Barbie.Internal.ProofB -- | Barbie-types with products have a canonical proof of instance. -- -- There is a default bproof implementation for Generic -- types, so instances can derived automatically. class (ConstraintsB b, ProductB b) => ProofB b bproof :: (ProofB b, ConstraintsOf c f b) => b (DictOf c f) bproof :: (ProofB b, CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b (DictOf c f) -- | Every type that admits a generic instance of ProductB and -- ConstraintsB, has a generic instance of ProofB as well. type CanDeriveGenericInstance b = (Generic (b (Target P)), GProof (ClassifyBarbie b) b (RecRep (b (Target F))), Rep (b (Target P)) ~ Repl' (Target F) (Target P) (RecRep (b (Target F)))) type ConstraintsOfMatchesGenericDeriv c f b = (ConstraintsOf c f b ~ GConstraintsOf c f (RecRep (b (Target F))), ConstraintsOf c f b ~ ConstraintByType (ClassifyBarbie b) c f (RecRep (b (Target F)))) type GConstraintsOf c f r = ConstraintByType (GClassifyBarbie r) c f r class GProof (bt :: BarbieType) b rep -- | Default implementation of bproof based on Generic. gbproofDefault :: forall b c f. (CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b (DictOf c f) instance Data.Barbie.Internal.ProofB.ProofB b' => Data.Barbie.Internal.ProofB.GProof bt b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.NonRec (b' (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) instance (Data.Barbie.Internal.ProofB.CanDeriveGenericInstance b, bt ~ Data.Barbie.Internal.Classification.ClassifyBarbie b) => Data.Barbie.Internal.ProofB.GProof bt b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.RecUsage (b (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F)))) instance Data.Barbie.Internal.ProofB.GProof bt b x => Data.Barbie.Internal.ProofB.GProof bt b (GHC.Generics.M1 _i _c x) instance Data.Barbie.Internal.ProofB.GProof bt b GHC.Generics.U1 instance (Data.Barbie.Internal.ProofB.GProof bt b l, Data.Barbie.Internal.ProofB.GProof bt b r) => Data.Barbie.Internal.ProofB.GProof bt b (l GHC.Generics.:*: r) instance Data.Barbie.Internal.ProofB.GProof 'Data.Barbie.Internal.Classification.WearBarbie b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.NonRec (Data.Barbie.Internal.Generics.Target (Data.Barbie.Internal.Generics.W Data.Barbie.Internal.Tags.F) a))) instance Data.Barbie.Internal.ProofB.GProof 'Data.Barbie.Internal.Classification.NonWearBarbie b (GHC.Generics.K1 GHC.Generics.R (Data.Barbie.Internal.Generics.NonRec (Data.Barbie.Internal.Generics.Target Data.Barbie.Internal.Tags.F a))) -- | Support for operating on Barbie-types with constrained functions. -- -- Consider the following function: -- --
--   showIt :: Show a => Maybe a -> Const String a
--   showIt = Const . show
--   
-- -- We would then like to be able to do: -- --
--   bmap showIt :: FunctorB b => b Maybe -> b (Const String)
--   
-- -- This however doesn't work because of the (Show a) -- constraint in the the type of showIt. -- -- This module adds support to overcome this problem. module Data.Barbie.Constraints -- | DictOf c f a is evidence that there exists an instance -- of c (f a). data DictOf c f a [PackedDict] :: c (f a) => DictOf c f a -- | Pack the dictionary associated with an instance. packDict :: c (f a) => DictOf c f a -- | Turn a constrained-function into an unconstrained one that uses the -- packed instance dictionary instead. requiringDict :: (c (f a) => r) -> (DictOf c f a -> r) -- | Instances of this class provide means to talk about constraints, both -- at compile-time, using ConstraintsOf and at run-time, in the -- form of class instance dictionaries, via adjProof. -- -- A manual definition would look like this: -- --
--   data T f = A (f Int) (f String) | B (f Bool) (f Int)
--   
--   instance ConstraintsB T where
--     type ConstraintsOf c f T
--       = (c (f Int), c (f String), c (f Bool))
--   
--     adjProof t = case t of
--       A x y -> A (Pair (packDict x) (packDict y))
--       B z w -> B (Pair (packDict z) (packDict w))
--   
-- -- There is a default implementation of ConstraintsOf for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic T
--   instance ConstraintsB T
--   
class FunctorB b => ConstraintsB b where { type family ConstraintsOf (c :: * -> Constraint) (f :: * -> *) b :: Constraint; type ConstraintsOf c f b = GConstraintsOf c f (RecRep (b (Target F))); } -- | Barbie-types with products have a canonical proof of instance. -- -- There is a default bproof implementation for Generic -- types, so instances can derived automatically. class (ConstraintsB b, ProductB b) => ProofB b bproof :: (ProofB b, ConstraintsOf c f b) => b (DictOf c f) bproof :: (ProofB b, CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b (DictOf c f) -- | A common Haskell idiom is to parameterise a datatype by a type * -- -> *, typically a functor or a GADT. These are like outfits of -- a Barbie, that turn her into a different doll. E.g. -- --
--   data Barbie f
--     = Barbie
--         { name :: f String
--         , age  :: f Int
--         }
--   
--   b1 :: Barbie Last       -- Barbie with a monoid structure
--   b2 :: Barbie (Const a)  -- Container Barbie
--   b3 :: Barbie Identity   -- Barbie's new clothes
--   
-- -- This module define the classes to work with these types and easily -- transform them. They all come with default instances based on -- Generic, so using them is as easy as: -- --
--   data Barbie f
--     = Barbie
--         { name :: f String
--         , age  :: f Int
--         }
--     deriving
--       ( Generic
--       , FunctorB, TraversableB, ProductB, ConstraintsB, ProofB
--       )
--   
--   deriving instance ConstraintsOf Show f Barbie => Show Barbie
--   deriving instance ConstraintsOf Eq   f Barbie => Eq   Barbie
--   
-- -- Sometimes one wants to use Barbie Identity and it may -- feels lik a second-class record type, where one needs to unpack values -- in each field. For those cases, we can leverage on closed -- type-families ang get the best of both worlds: -- --
--   data Bare
--   
--   type family Wear f a where
--     Wear Bare a = a
--     Wear f      a = f a
--   
--   data SignUpForm f
--     = SignUpForm'
--         { username  :: Wear f String,
--         , password  :: Wear f String
--         , mailingOk :: Wear f Boolean
--         }
--     deriving ( ..., BareB)
--   
--   type SignUpRaw  = SignUpForm Maybe
--   type SignUpData = SignUpForm Bare
--   
--   formData = SignUpForm "jbond" "shaken007" False :: SignUpData
--   
module Data.Barbie -- | Barbie-types that can be mapped over. Instances of FunctorB -- should satisfy the following laws: -- --
--   bmap id = id
--   bmap f . bmap g = bmap (f . g)
--   
-- -- There is a default bmap implementation for Generic -- types, so instances can derived automatically. class FunctorB b bmap :: FunctorB b => (forall a. f a -> g a) -> b f -> b g bmap :: (FunctorB b, CanDeriveGenericInstance b) => (forall a. f a -> g a) -> b f -> b g -- | Barbie-types that can be traversed from left to right. Instances -- should satisfy the following laws: -- --
--    t . btraverse f = btraverse (t . f)  -- naturality
--   btraverse Identity = Identity         -- identity
--   btraverse (Compose . fmap g . f) = Compose . fmap (btraverse g) . btraverse f -- composition
--   
-- -- There is a default btraverse implementation for Generic -- types, so instances can derived automatically. class FunctorB b => TraversableB b btraverse :: (TraversableB b, Applicative t) => (forall a. f a -> t (g a)) -> b f -> t (b g) btraverse :: (TraversableB b, Applicative t, CanDeriveGenericInstance b) => (forall a. f a -> t (g a)) -> b f -> t (b g) -- | Evaluate each action in the structure from left to right, and collect -- the results. bsequence :: (Applicative f, TraversableB b) => b (Compose f g) -> f (b g) -- | Barbie-types that can form products, subject to the laws: -- --
--   bmap (Pair a _) . uncurry . bprod = fst
--   bmap (Pair _ b) . uncurry . bprod = snd
--   
-- -- Notice that because of the laws, having an internal product structure -- is not enough to have a lawful instance. E.g. -- --
--   data Ok  f = Ok {o1 :: f String, o2 :: f Int}        -- has an instance
--   data Bad f = Bad{b1 :: f String, hiddenFromArg: Int} -- no lawful instance
--   
-- -- Intuitively, the laws for this class require that b hides no -- structure from its argument f. Because of this, any x :: -- forall a . f a determines a unique value of b f, -- witnessed by the buniq method. Formally: -- --
--   const (buniq x) = bmap (const x)
--   
-- -- There is a default implementation of bprod and buniq for -- Generic types, so instances can derived automatically. class FunctorB b => ProductB b bprod :: ProductB b => b f -> b g -> b (Product f g) buniq :: ProductB b => (forall a. f a) -> b f bprod :: (ProductB b, CanDeriveGenericInstance b) => b f -> b g -> b (Product f g) buniq :: (ProductB b, CanDeriveGenericInstance' b) => (forall a. f a) -> b f -- | Like bprod, but returns a binary Prod, instead of -- Product, which composes better. -- -- See /*/ for usage. (/*/) :: ProductB b => b f -> b g -> b (Prod '[f, g]) infixr 4 /*/ -- | Similar to /*/ but one of the sides is already a 'Prod fs'. -- -- Note that /*, /*/ and uncurryn are meant to be -- used together: /* and /*/ combine b f1, b f2...b -- fn into a single product that can then be consumed by using -- uncurryn on an n-ary function. E.g. -- --
--   f :: f a -> g a -> h a -> i a
--   
--   bmap (uncurryn f) (bf /* bg /*/ bh)
--   
(/*) :: ProductB b => b f -> b (Prod fs) -> b (Prod (f : fs)) infixr 4 /* -- | An alias of bprod, since this is like a zip for -- Barbie-types. bzip :: ProductB b => b f -> b g -> b (Product f g) -- | An equivalent of unzip for Barbie-types. bunzip :: ProductB b => b (Product f g) -> (b f, b g) -- | An equivalent of zipWith for Barbie-types. bzipWith :: ProductB b => (forall a. f a -> g a -> h a) -> b f -> b g -> b h -- | An equivalent of zipWith3 for Barbie-types. bzipWith3 :: ProductB b => (forall a. f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i -- | An equivalent of zipWith4 for Barbie-types. bzipWith4 :: ProductB b => (forall a. f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j -- | The Wear type-function allows one to define a Barbie-type as -- --
--   data B f
--     = B { f1 :: Wear f Int
--         , f2 :: Wear f Bool
--         }
--   
-- -- This way, one can use Bare as a phantom that denotes no functor -- around the typw: -- --
--   B { f1 :: 5, f2 = True } :: B Bare
--   
-- | Bare is the only type such that Wear Bare a ~ -- a'. data Bare a -- | Class of Barbie-types defined using Wear and can therefore have -- Bare versions. Must satisfy: -- --
--   bcover . bstrip = id
--   bstrip . bcover = id
--   
class FunctorB b => BareB b bstrip :: BareB b => b Identity -> b Bare bcover :: BareB b => b Bare -> b Identity bstrip :: (BareB b, CanDeriveGenericInstance b) => b Identity -> b Bare bcover :: (BareB b, CanDeriveGenericInstance' b) => b Bare -> b Identity -- | Generalization of bstrip to arbitrary functors bstripFrom :: BareB b => (forall a. f a -> a) -> b f -> b Bare -- | Generalization of bcover to arbitrary functors bcoverWith :: BareB b => (forall a. a -> f a) -> b Bare -> b f -- | Instances of this class provide means to talk about constraints, both -- at compile-time, using ConstraintsOf and at run-time, in the -- form of class instance dictionaries, via adjProof. -- -- A manual definition would look like this: -- --
--   data T f = A (f Int) (f String) | B (f Bool) (f Int)
--   
--   instance ConstraintsB T where
--     type ConstraintsOf c f T
--       = (c (f Int), c (f String), c (f Bool))
--   
--     adjProof t = case t of
--       A x y -> A (Pair (packDict x) (packDict y))
--       B z w -> B (Pair (packDict z) (packDict w))
--   
-- -- There is a default implementation of ConstraintsOf for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic T
--   instance ConstraintsB T
--   
class FunctorB b => ConstraintsB b where { type family ConstraintsOf (c :: * -> Constraint) (f :: * -> *) b :: Constraint; type ConstraintsOf c f b = GConstraintsOf c f (RecRep (b (Target F))); } -- | Adjoint a proof-of-instance to a barbie-type. adjProof :: forall c f. (ConstraintsB b, ConstraintsOf c f b) => b f -> b (Product (DictOf c f) f) -- | Adjoint a proof-of-instance to a barbie-type. adjProof :: forall c f. (ConstraintsB b, CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b f -> b (Product (DictOf c f) f) -- | Barbie-types with products have a canonical proof of instance. -- -- There is a default bproof implementation for Generic -- types, so instances can derived automatically. class (ConstraintsB b, ProductB b) => ProofB b bproof :: (ProofB b, ConstraintsOf c f b) => b (DictOf c f) bproof :: (ProofB b, CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b (DictOf c f) -- | A wrapper for Barbie-types, providing useful instances. newtype Barbie b (f :: * -> *) Barbie :: b f -> Barbie b [getBarbie] :: Barbie b -> b f -- | We get a container of a's for any Barbie-type when we make it -- wear a (Const a) . The Container wrapper gives -- us the expected instances for a container type. module Data.Barbie.Container -- | Wrapper for container-Barbies. newtype Container b a Container :: b (Const a) -> Container b a [getContainer] :: Container b a -> b (Const a) instance GHC.Generics.Generic (Data.Barbie.Container.Container b a) instance GHC.Classes.Eq (b (Data.Functor.Const.Const a)) => GHC.Classes.Eq (Data.Barbie.Container.Container b a) instance GHC.Classes.Ord (b (Data.Functor.Const.Const a)) => GHC.Classes.Ord (Data.Barbie.Container.Container b a) instance GHC.Read.Read (b (Data.Functor.Const.Const a)) => GHC.Read.Read (Data.Barbie.Container.Container b a) instance GHC.Show.Show (b (Data.Functor.Const.Const a)) => GHC.Show.Show (Data.Barbie.Container.Container b a) instance Data.Barbie.Internal.Functor.FunctorB b => GHC.Base.Functor (Data.Barbie.Container.Container b) instance Data.Barbie.Internal.Traversable.TraversableB b => Data.Foldable.Foldable (Data.Barbie.Container.Container b) instance Data.Barbie.Internal.Traversable.TraversableB b => Data.Traversable.Traversable (Data.Barbie.Container.Container b) instance Data.Barbie.Internal.Product.ProductB b => GHC.Base.Applicative (Data.Barbie.Container.Container b)