-- 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.0.2.0 -- | 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)
--       ⋮
--   
-- | Deprecated: The module is no longer part of the main api and will -- be removed module Data.Functor.Prod -- | Product of n functors. data Prod :: [k -> Type] -> k -> Type [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. type family (++) l r :: [k] -- | 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
--   
type family Curried t 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) -- | Sometimes one needs a type like Barbie Identity 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: -- --
--   data Bare
--   data Covered
--   
--   type family Wear t f a where
--     Wear Bare    f a = a
--     Wear Covered f a = f a
--   
--   data SignUpForm t f
--     = SignUpForm
--         { username  :: Wear t f String,
--         , password  :: Wear t f String
--         , mailingOk :: Wear t f Bool
--         }
--    instance FunctorB (SignUpForm Covered)
--    instance TraversableB (SignUpForm Covered)
--    ...,
--    instance BareB SignUpForm
--   
--   type SignUpRaw  = SignUpForm Covered Maybe
--   type SignUpData = SignUpForm Bare Identity
--   
--   formData = SignUpForm "jbond" "shaken007" False :: SignUpData
--   
module Barbies.Bare -- | The Wear type-function allows one to define a Barbie-type as -- --
--   data B t f
--     = B { f1 :: Wear t f Int
--         , f2 :: Wear t f Bool
--         }
--   
-- -- This gives rise to two rather different types: -- -- -- --
--   B { f1 :: 5, f2 = True } :: B Bare f
--   
type family Wear t f a data Bare data Covered -- | Class of Barbie-types defined using Wear and can therefore have -- Bare versions. Must satisfy: -- --
--   bcover . bstrip = id
--   bstrip . bcover = id
--   
class FunctorB (b Covered) => BareB b bstrip :: BareB b => b Covered Identity -> b Bare Identity bcover :: BareB b => b Bare Identity -> b Covered Identity bstrip :: (BareB b, CanDeriveBareB b) => b Covered Identity -> b Bare Identity bcover :: (BareB b, CanDeriveBareB b) => b Bare Identity -> b Covered Identity -- | Generalization of bstrip to arbitrary functors bstripFrom :: BareB b => (forall a. f a -> a) -> b Covered f -> b Bare Identity -- | Generalization of bcover to arbitrary functors bcoverWith :: BareB b => (forall a. a -> f a) -> b Bare Identity -> b Covered f -- | Like the Wear family, but with two wrappers f and -- g instead of one. This is useful if you have a data-type -- where f is parametric but g is not, consider this: -- --
--   data T t f =
--     T { f1 :: Wear    t f [Bool]
--       , f2 :: Wear    t f (Sum Int)
--       , f3 :: WearTwo t f Sum Int
--       , f4 :: WearTwo t f Max Int
--       }
--   
-- -- with x :: T Covered Option we would have -- --
--   f1 x :: IO (Option [Bool])
--   f2 x :: IO (Option (Sum Int))
--   f3 x :: IO (Option (Sum Int))
--   f4 x :: IO (Option (Max Int))
--   
-- -- and with y :: T Bare Identity we would have -- --
--   f1 y :: Int
--   f2 y :: Sum Int
--   f3 y :: Int
--   f4 y :: Int
--   
-- -- Note how (Option (Sum Int)) (or Max) has a nice -- Semigroup instance that we can use to merge two (covered) barbies, -- while WearTwo removes the wrapper for the bare barbie. type family WearTwo t f g a -- | Deprecated: Use Barbies.Bare module Data.Barbie.Bare -- | The Wear type-function allows one to define a Barbie-type as -- --
--   data B t f
--     = B { f1 :: Wear t f Int
--         , f2 :: Wear t f Bool
--         }
--   
-- -- This gives rise to two rather different types: -- -- -- --
--   B { f1 :: 5, f2 = True } :: B Bare f
--   
type family Wear t f a data Bare data Covered -- | Class of Barbie-types defined using Wear and can therefore have -- Bare versions. Must satisfy: -- --
--   bcover . bstrip = id
--   bstrip . bcover = id
--   
class FunctorB (b Covered) => BareB b bstrip :: BareB b => b Covered Identity -> b Bare Identity bcover :: BareB b => b Bare Identity -> b Covered Identity bstrip :: (BareB b, CanDeriveBareB b) => b Covered Identity -> b Bare Identity bcover :: (BareB b, CanDeriveBareB b) => b Bare Identity -> b Covered Identity -- | Generalization of bstrip to arbitrary functors bstripFrom :: BareB b => (forall a. f a -> a) -> b Covered f -> b Bare Identity -- | Generalization of bcover to arbitrary functors bcoverWith :: BareB b => (forall a. a -> f a) -> b Bare Identity -> b Covered f -- | Functors on indexed-types. module Data.Functor.Transformer -- | Functor from indexed-types to indexed-types. Instances of -- FunctorT should satisfy the following laws: -- --
--   tmap id = id
--   tmap f . tmap g = tmap (f . g)
--   
-- -- There is a default tmap implementation for Generic -- types, so instances can derived automatically. class FunctorT (t :: (k -> Type) -> k' -> Type) tmap :: FunctorT t => (forall a. f a -> g a) -> forall x. t f x -> t g x tmap :: forall f g x. (FunctorT t, CanDeriveFunctorT t f g x) => (forall a. 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: -- --
--    t . ttraverse f   = ttraverse (t . f)  -- naturality
--   ttraverse Identity = Identity           -- identity
--   ttraverse (Compose . fmap g . f) = Compose . fmap (ttraverse g) . ttraverse f -- composition
--   
-- -- There is a default ttraverse implementation for Generic -- types, so instances can derived automatically. class FunctorT t => TraversableT (t :: (k -> Type) -> k' -> Type) ttraverse :: (TraversableT t, Applicative e) => (forall a. f a -> e (g a)) -> forall x. t f x -> e (t g x) ttraverse :: (TraversableT t, Applicative e, CanDeriveTraversableT t f g x) => (forall a. f a -> e (g a)) -> t f x -> e (t g x) -- | Map each element to an action, evaluate these actions from left to -- right, and ignore the results. ttraverse_ :: (TraversableT t, Applicative e) => (forall a. f a -> e c) -> t f x -> e () -- | Map each element to a monoid, and combine the results. tfoldMap :: (TraversableT t, Monoid m) => (forall a. f a -> m) -> t f x -> m -- | Evaluate each action in the structure from left to right, and collect -- the results. tsequence :: (Applicative e, TraversableT t) => t (Compose e f) x -> e (t f x) -- | A version of tsequence with f specialized to -- Identity. tsequence' :: (Applicative e, TraversableT t) => t e x -> e (t Identity x) -- | A FunctorT where the effects can be distributed to the fields: -- tdistribute 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 TraversableT, with -- tdistribute the dual of tsequence and tcotraverse -- the dual of ttraverse. As such, instances need to satisfy these -- laws: -- --
--   tdistribute . h = tmap (Compose . h . getCompose) . tdistribute    -- naturality
--   tdistribute . Identity = tmap (Compose . Identity)                 -- identity
--   tdistribute . Compose = fmap (Compose . Compose . fmap getCompose . getCompose) . tdistribute . fmap distribute -- composition
--   
-- -- By specializing f to ((->) a) and g to -- Identity, we can define a function that decomposes a function -- on distributive transformers into a collection of simpler functions: -- --
--   tdecompose :: DistributiveT b => (a -> b Identity) -> b ((->) a)
--   tdecompose = tmap (fmap runIdentity . getCompose) . tdistribute
--   
-- -- Lawful instances of the class can then be characterized as those that -- satisfy: -- --
--   trecompose . tdecompose = id
--   tdecompose . trecompose = id
--   
-- -- 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 tdistribute based on -- Generic. Intuitively, it works on product types where the shape -- of a pure value is uniquely defined and every field is covered by the -- argument f. class FunctorT t => DistributiveT (t :: (Type -> Type) -> i -> Type) tdistribute :: (DistributiveT t, Functor f) => f (t g x) -> t (Compose f g) x tdistribute :: forall f g x. (DistributiveT t, CanDeriveDistributiveT t f g x) => f (t g x) -> t (Compose f g) x -- | A version of tdistribute with g specialized to -- Identity. tdistribute' :: (DistributiveT t, Functor f) => f (t Identity x) -> t f x -- | Dual of ttraverse tcotraverse :: (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 :: DistributiveT t => (a -> t Identity x) -> t ((->) a) x -- | Recompose a decomposed function. trecompose :: FunctorT t => t ((->) a) x -> a -> t Identity x -- | A FunctorT with application, providing operations to: -- -- -- -- It should satisfy the following laws: -- -- -- --
--   tmap ((Pair a b) -> Pair (f a) (g b)) (u `tprod' v) = tmap f u `tprod' tmap g v
--   
-- -- -- --
--   tmap ((Pair _ b) -> b) (tpure e `tprod' v) = v
--   tmap ((Pair a _) -> a) (u `tprod' tpure e) = u
--   
-- -- -- --
--   tmap ((Pair a (Pair b c)) -> Pair (Pair a b) c) (u `tprod' (v `tprod' w)) = (u `tprod' v) `tprod' w
--   
-- -- It is to FunctorT in the same way is Applicative relates -- to Functor. For a presentation of Applicative as a -- monoidal functor, see Section 7 of Applicative Programming with -- Effects. -- -- There is a default implementation of tprod and tpure -- based on Generic. Intuitively, it works on types where the -- value of tpure is uniquely defined. This corresponds rougly to -- record types (in the presence of sums, there would be several -- candidates for tpure), where every field is either a -- Monoid or covered by the argument f. class FunctorT t => ApplicativeT (t :: (k -> Type) -> (k' -> Type)) tpure :: ApplicativeT t => (forall a. f a) -> forall x. t f x tprod :: ApplicativeT t => t f x -> t g x -> t (f `Product` g) x tpure :: (ApplicativeT t, CanDeriveApplicativeT t f f x) => (forall a. f a) -> t f x tprod :: (ApplicativeT t, CanDeriveApplicativeT t f g x) => t f x -> t g x -> t (f `Product` g) x -- | An alias of tprod. tzip :: ApplicativeT t => t f x -> t g x -> t (f `Product` g) x -- | An equivalent of unzip. tunzip :: ApplicativeT t => t (f `Product` g) x -> (t f x, t g x) -- | An equivalent of zipWith. tzipWith :: ApplicativeT t => (forall a. f a -> g a -> h a) -> t f x -> t g x -> t h x -- | An equivalent of zipWith3. tzipWith3 :: ApplicativeT t => (forall a. f a -> g a -> h a -> i a) -> t f x -> t g x -> t h x -> t i x -- | An equivalent of zipWith4. tzipWith4 :: ApplicativeT t => (forall a. 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 Compose or ReaderT. In -- that sense, MonadT is similar to MonadTrans but with -- additional structure (see also mmorph's MMonad class). -- -- Notice though that while lift assumes a Monad instance -- of the value to be lifted, tlift has no such constraint. This -- means we cannot have instances for most "monad transformers", since -- lifting typically involves an fmap. -- -- MonadT also corresponds to the indexed-monad of Kleisli -- arrows of outrageous fortune. -- -- Instances of this class should to satisfy the monad laws. They laws -- can stated either in terms of (tlift, tjoin) or -- (tlift, tembed). In the former: -- --
--   tmap h . tlift = tlift . h
--   tmap h . tjoin = tjoin . tmap (tmap h)
--   tjoin . tlift  = id
--   tjoin . 'tmap tlift' = id
--   tjoin . tjoin = tjoin . tmap tjoin
--   
-- -- In the latter: -- --
--   tembed f . tlift = f
--   tembed tlift = id
--   tembed f . tembed g = tembed (tembed f . g)
--   
class FunctorT t => MonadT t -- | Lift a functor to a transformed functor. tlift :: 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 :: MonadT t => t (t f) a -> t f a -- | Analogous to (=<<). tembed :: (MonadT t, MonadT t) => (forall x. 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 AllT, and at run-time, in the form of -- Dict, via taddDicts. -- -- A manual definition would look like this: -- --
--   data T f a = A (f Int) (f String) | B (f Bool) (f Int)
--   
--   instance ConstraintsT T where
--     type AllT c T = (c Int, c String, c Bool)
--   
--     taddDicts t = case t of
--       A x y -> A (Pair Dict x) (Pair Dict y)
--       B z w -> B (Pair Dict z) (Pair Dict w)
--   
-- -- Now, when we given a T f, if we need to use the Show -- instance of their fields, we can use: -- --
--   taddDicts :: AllT Show t => t f -> t (Dict Show `Product' f)
--   
-- -- There is a default implementation of ConstraintsT for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic (T f a)
--   instance ConstraintsT T
--   
class FunctorT t => ConstraintsT (t :: (kl -> *) -> (kr -> *)) where { -- | AllT c t should contain a constraint c a for -- each a occurring under an f in t f. -- -- For requiring constraints of the form c (f a), use -- AllTF. type family AllT (c :: k -> Constraint) t :: Constraint; type AllT c t = GAll 1 c (GAllRepT t); } taddDicts :: forall c f x. (ConstraintsT t, AllT c t) => t f x -> t (Dict c `Product` f) x taddDicts :: forall c f x. (ConstraintsT t, CanDeriveConstraintsT c t f x, AllT c t) => t f x -> t (Dict c `Product` f) x -- | Similar to AllT but will put the functor argument f -- between the constraint c and the type a. type AllTF c f t = AllT (ClassF c f) t -- | Like tmap but a constraint is allowed to be required on each -- element of t. tmapC :: forall c t f g x. (AllT c t, ConstraintsT t) => (forall a. c a => f a -> g a) -> t f x -> t g x -- | Like ttraverse but with a constraint on the elements of -- t. ttraverseC :: forall c t f g e x. (TraversableT t, ConstraintsT t, AllT c t, Applicative e) => (forall a. c a => f a -> e (g a)) -> t f x -> e (t g x) newtype Rec (p :: Type) a x Rec :: K1 R a x -> Rec a x [unRec] :: Rec a x -> K1 R a x -- | Functors from indexed-types to types. module Data.Functor.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 :: (k -> Type) -> Type) bmap :: FunctorB b => (forall a. f a -> g a) -> b f -> b g bmap :: forall f g. (FunctorB b, CanDeriveFunctorB b f g) => (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 :: (k -> Type) -> Type) btraverse :: (TraversableB b, Applicative e) => (forall a. f a -> e (g a)) -> b f -> e (b g) btraverse :: (TraversableB b, Applicative e, CanDeriveTraversableB b f g) => (forall a. f a -> e (g a)) -> b f -> 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. f a -> e c) -> b f -> e () -- | Map each element to a monoid, and combine the results. bfoldMap :: (TraversableB b, Monoid m) => (forall a. f a -> m) -> b f -> m -- | Evaluate each action in the structure from left to right, and collect -- the results. bsequence :: (Applicative e, TraversableB b) => b (Compose e f) -> e (b f) -- | A version of bsequence with f specialized to -- Identity. bsequence' :: (Applicative e, TraversableB b) => b e -> e (b Identity) -- | A FunctorB where the effects can be distributed to the fields: -- bdistribute 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 TraversableB, with -- bdistribute the dual of bsequence and bcotraverse -- the dual of btraverse. As such, instances need to satisfy these -- laws: -- --
--   bdistribute . h = bmap (Compose . h . getCompose) . bdistribute    -- naturality
--   bdistribute . Identity = bmap (Compose . Identity)                 -- identity
--   bdistribute . Compose = bmap (Compose . Compose . fmap getCompose . getCompose) . bdistribute . fmap bdistribute -- composition
--   
-- -- By specializing f to ((->) a) and g to -- Identity, we can define a function that decomposes a function -- on distributive barbies into a collection of simpler functions: -- --
--   bdecompose :: DistributiveB b => (a -> b Identity) -> b ((->) a)
--   bdecompose = bmap (fmap runIdentity . getCompose) . bdistribute
--   
-- -- Lawful instances of the class can then be characterized as those that -- satisfy: -- --
--   brecompose . bdecompose = id
--   bdecompose . brecompose = id
--   
-- -- 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 bdistribute based on -- Generic. Intuitively, it works on product types where the shape -- of a pure value is uniquely defined and every field is covered by the -- argument f. class (FunctorB b) => DistributiveB (b :: (k -> Type) -> Type) bdistribute :: (DistributiveB b, Functor f) => f (b g) -> b (Compose f g) bdistribute :: forall f g. (DistributiveB b, CanDeriveDistributiveB b f g) => Functor f => f (b g) -> b (Compose f g) -- | A version of bdistribute with g specialized to -- Identity. bdistribute' :: (DistributiveB b, Functor f) => f (b Identity) -> b f -- | Dual of btraverse 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 FunctorB with application, providing operations to: -- -- -- -- It should satisfy the following laws: -- -- -- --
--   bmap ((Pair a b) -> Pair (f a) (g b)) (u `bprod' v) = bmap f u `bprod' bmap g v
--   
-- -- -- --
--   bmap ((Pair _ b) -> b) (bpure e `bprod' v) = v
--   bmap ((Pair a _) -> a) (u `bprod' bpure e) = u
--   
-- -- -- --
--   bmap ((Pair a (Pair b c)) -> Pair (Pair a b) c) (u `bprod' (v `bprod' w)) = (u `bprod' v) `bprod' w
--   
-- -- It is to FunctorB in the same way as Applicative relates -- to Functor. For a presentation of Applicative as a -- monoidal functor, see Section 7 of Applicative Programming with -- Effects. -- -- There is a default implementation of bprod and bpure -- based on Generic. Intuitively, it works on types where the -- value of bpure is uniquely defined. This corresponds rougly to -- record types (in the presence of sums, there would be several -- candidates for bpure), where every field is either a -- Monoid or covered by the argument f. class FunctorB b => ApplicativeB (b :: (k -> Type) -> Type) bpure :: ApplicativeB b => (forall a. f a) -> b f bprod :: ApplicativeB b => b f -> b g -> b (f `Product` g) bpure :: (ApplicativeB b, CanDeriveApplicativeB b f f) => (forall a. f a) -> b f bprod :: (ApplicativeB b, CanDeriveApplicativeB b f g) => b f -> b g -> b (f `Product` g) -- | An alias of bprod, since this is like a zip. bzip :: ApplicativeB b => b f -> b g -> b (f `Product` g) -- | An equivalent of unzip. bunzip :: ApplicativeB b => b (f `Product` g) -> (b f, b g) -- | An equivalent of zipWith. bzipWith :: ApplicativeB b => (forall a. f a -> g a -> h a) -> b f -> b g -> b h -- | An equivalent of zipWith3. bzipWith3 :: ApplicativeB b => (forall a. f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i -- | An equivalent of zipWith4. bzipWith4 :: ApplicativeB b => (forall a. 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 AllB, and at run-time, in the form of -- Dict, via baddDicts. -- -- 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 AllB c T = (c Int, c String, c Bool)
--   
--     baddDicts t = case t of
--       A x y -> A (Pair Dict x) (Pair Dict y)
--       B z w -> B (Pair Dict z) (Pair Dict w)
--   
-- -- Now, when we given a T f, if we need to use the Show -- instance of their fields, we can use: -- --
--   baddDicts :: AllB Show b => b f -> b (Dict Show `Product' f)
--   
-- -- There is a default implementation of ConstraintsB for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic (T f)
--   instance ConstraintsB T
--   
class FunctorB b => ConstraintsB (b :: (k -> *) -> *) where { -- | AllB c b should contain a constraint c a for -- each a occurring under an f in b f. E.g.: -- --
    --   AllB Show Person ~ (Show String, Show Int)
    --   
-- -- For requiring constraints of the form c (f a), use -- AllBF. type family AllB (c :: k -> Constraint) b :: Constraint; type AllB c b = GAll 0 c (GAllRepB b); } baddDicts :: forall c f. (ConstraintsB b, AllB c b) => b f -> b (Dict c `Product` f) baddDicts :: forall c f. (ConstraintsB b, CanDeriveConstraintsB c b f, AllB c b) => b f -> b (Dict c `Product` f) -- | Similar to AllB but will put the functor argument f -- between the constraint c and the type a. For -- example: -- --
--   AllB  Show   Person ~ (Show    String,  Show    Int)
--   AllBF Show f Person ~ (Show (f String), Show (f Int))
--   
--   
type AllBF c f b = AllB (ClassF c f) b -- | Similar to baddDicts but can produce the instance dictionaries -- "out of the blue". bdicts :: forall c b. (ConstraintsB b, ApplicativeB b, AllB c b) => b (Dict c) -- | Like bmap but a constraint is allowed to be required on each -- element of b -- -- E.g. If all fields of b are Showable then you could -- store each shown value in it's slot using Const: -- --
--   showFields :: (AllB Show b, ConstraintsB b) => b Identity -> b (Const String)
--   showFields = bmapC @Show showField
--     where
--       showField :: forall a. Show a => Identity a -> Const String a
--       showField (Identity a) = Const (show a)
--   
bmapC :: forall c b f g. (AllB c b, ConstraintsB b) => (forall a. c a => f a -> g a) -> b f -> b g bfoldMapC :: forall c b m f. (TraversableB b, ConstraintsB b, AllB c b, Monoid m) => (forall a. c a => f a -> m) -> b f -> m -- | Like btraverse but with a constraint on the elements of -- b. btraverseC :: forall c b f g e. (TraversableB b, ConstraintsB b, AllB c b, Applicative e) => (forall a. c a => f a -> e (g a)) -> b f -> e (b g) -- | Like bpure but a constraint is allowed to be required on each -- element of b. bpureC :: forall c f b. (AllB c b, ConstraintsB b, ApplicativeB b) => (forall a. c a => f a) -> b f -- | Like bzipWith but with a constraint on the elements of -- b. bzipWithC :: forall c b f g h. (AllB c b, ConstraintsB b, ApplicativeB b) => (forall a. c a => f a -> g a -> h a) -> b f -> b g -> b h -- | Like bzipWith3 but with a constraint on the elements of -- b. bzipWith3C :: forall c b f g h i. (AllB c b, ConstraintsB b, ApplicativeB b) => (forall a. c a => f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i -- | Like bzipWith4 but with a constraint on the elements of -- b. bzipWith4C :: forall c b f g h i j. (AllB c b, ConstraintsB b, ApplicativeB b) => (forall a. c a => f a -> g a -> h a -> i a -> j a) -> b f -> b g -> b h -> b i -> b j -- | Builds a b f, by applying mempty on every field of -- b. bmempty :: forall f b. (AllBF Monoid f b, ConstraintsB b, ApplicativeB b) => b f newtype Rec (p :: Type) a x Rec :: K1 R a x -> Rec a x [unRec] :: Rec a x -> K1 R a x -- | Deprecated: Use Data.Functor.Barbie or Barbie.Constraints module Data.Barbie.Constraints -- | Dict c a is evidence that there exists an instance of -- c a. -- -- It is essentially equivalent to Dict (c a) from the -- constraints package, but because of its kind, it allows us to -- define things like Dict Show. data Dict c a [Dict] :: c a => Dict c a -- | Turn a constrained-function into an unconstrained one that uses the -- packed instance dictionary instead. requiringDict :: (c a => r) -> Dict c a -> r -- | Instances of this class provide means to talk about constraints, both -- at compile-time, using AllB, and at run-time, in the form of -- Dict, via baddDicts. -- -- 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 AllB c T = (c Int, c String, c Bool)
--   
--     baddDicts t = case t of
--       A x y -> A (Pair Dict x) (Pair Dict y)
--       B z w -> B (Pair Dict z) (Pair Dict w)
--   
-- -- Now, when we given a T f, if we need to use the Show -- instance of their fields, we can use: -- --
--   baddDicts :: AllB Show b => b f -> b (Dict Show `Product' f)
--   
-- -- There is a default implementation of ConstraintsB for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic (T f)
--   instance ConstraintsB T
--   
class FunctorB b => ConstraintsB (b :: (k -> *) -> *) where { -- | AllB c b should contain a constraint c a for -- each a occurring under an f in b f. E.g.: -- --
    --   AllB Show Person ~ (Show String, Show Int)
    --   
-- -- For requiring constraints of the form c (f a), use -- AllBF. type family AllB (c :: k -> Constraint) b :: Constraint; type AllB c b = GAll 0 c (GAllRepB b); } baddDicts :: forall c f. (ConstraintsB b, AllB c b) => b f -> b (Dict c `Product` f) baddDicts :: forall c f. (ConstraintsB b, CanDeriveConstraintsB c b f, AllB c b) => b f -> b (Dict c `Product` f) class (ConstraintsB b, ProductB b) => ProductBC (b :: (k -> Type) -> Type) bdicts :: (ProductBC b, AllB c b) => b (Dict c) bdicts :: (ProductBC b, CanDeriveProductBC c b, AllB c b) => b (Dict c) -- | Like bmap but a constraint is allowed to be required on each -- element of b -- -- E.g. If all fields of b are Showable then you could -- store each shown value in it's slot using Const: -- --
--   showFields :: (AllB Show b, ConstraintsB b) => b Identity -> b (Const String)
--   showFields = bmapC @Show showField
--     where
--       showField :: forall a. Show a => Identity a -> Const String a
--       showField (Identity a) = Const (show a)
--   
bmapC :: forall c b f g. (AllB c b, ConstraintsB b) => (forall a. c a => f a -> g a) -> b f -> b g -- | Like btraverse but with a constraint on the elements of -- b. btraverseC :: forall c b f g e. (TraversableB b, ConstraintsB b, AllB c b, Applicative e) => (forall a. c a => f a -> e (g a)) -> b f -> e (b g) -- | Similar to AllB but will put the functor argument f -- between the constraint c and the type a. For -- example: -- --
--   AllB  Show   Person ~ (Show    String,  Show    Int)
--   AllBF Show f Person ~ (Show (f String), Show (f Int))
--   
--   
type AllBF c f b = AllB (ClassF c f) b -- | ClassF has one universal instance that makes ClassF -- c f a equivalent to c (f a). However, we have -- --
--   'ClassF c f :: k -> Constraint
--   
-- -- This is useful since it allows to define constraint-constructors like -- ClassF Monoid Maybe class c (f a) => ClassF c f a -- | Like ClassF but for binary relations. class c (f a) (g a) => ClassFG c f g a -- | Deprecated: Use Data.Functor.Barbie or Barbies instead 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 :: (k -> Type) -> Type) bmap :: FunctorB b => (forall a. f a -> g a) -> b f -> b g bmap :: forall f g. (FunctorB b, CanDeriveFunctorB b f g) => (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 :: (k -> Type) -> Type) btraverse :: (TraversableB b, Applicative e) => (forall a. f a -> e (g a)) -> b f -> e (b g) btraverse :: (TraversableB b, Applicative e, CanDeriveTraversableB b f g) => (forall a. f a -> e (g a)) -> b f -> 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. f a -> e c) -> b f -> e () -- | Map each element to a monoid, and combine the results. bfoldMap :: (TraversableB b, Monoid m) => (forall a. f a -> m) -> b f -> m -- | Evaluate each action in the structure from left to right, and collect -- the results. bsequence :: (Applicative e, TraversableB b) => b (Compose e f) -> e (b f) -- | A version of bsequence with f specialized to -- Identity. bsequence' :: (Applicative e, TraversableB b) => b e -> e (b Identity) -- | Deprecated: Use ApplicativeB class ApplicativeB b => ProductB (b :: (k -> Type) -> Type) bprod :: ProductB b => b f -> b g -> b (f `Product` g) -- | Deprecated: Use bpure buniq :: ProductB b => (forall a. f a) -> b f bprod :: (ProductB b, CanDeriveProductB b f g) => b f -> b g -> b (f `Product` g) -- | Deprecated: Use bpure buniq :: (ProductB b, CanDeriveProductB b f f) => (forall a. f a) -> b f type CanDeriveProductB b f g = (GenericN (b f), GenericN (b g), GenericN (b (f `Product` g)), GProductB f g (RepN (b f)) (RepN (b g)) (RepN (b (f `Product` g)))) -- | An alias of bprod, since this is like a zip. bzip :: ApplicativeB b => b f -> b g -> b (f `Product` g) -- | An equivalent of unzip. bunzip :: ApplicativeB b => b (f `Product` g) -> (b f, b g) -- | An equivalent of zipWith. bzipWith :: ApplicativeB b => (forall a. f a -> g a -> h a) -> b f -> b g -> b h -- | An equivalent of zipWith3. bzipWith3 :: ApplicativeB b => (forall a. f a -> g a -> h a -> i a) -> b f -> b g -> b h -> b i -- | An equivalent of zipWith4. bzipWith4 :: ApplicativeB b => (forall a. 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 AllB, and at run-time, in the form of -- Dict, via baddDicts. -- -- 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 AllB c T = (c Int, c String, c Bool)
--   
--     baddDicts t = case t of
--       A x y -> A (Pair Dict x) (Pair Dict y)
--       B z w -> B (Pair Dict z) (Pair Dict w)
--   
-- -- Now, when we given a T f, if we need to use the Show -- instance of their fields, we can use: -- --
--   baddDicts :: AllB Show b => b f -> b (Dict Show `Product' f)
--   
-- -- There is a default implementation of ConstraintsB for -- Generic types, so in practice one will simply do: -- --
--   derive instance Generic (T f)
--   instance ConstraintsB T
--   
class FunctorB b => ConstraintsB (b :: (k -> *) -> *) where { -- | AllB c b should contain a constraint c a for -- each a occurring under an f in b f. E.g.: -- --
    --   AllB Show Person ~ (Show String, Show Int)
    --   
-- -- For requiring constraints of the form c (f a), use -- AllBF. type family AllB (c :: k -> Constraint) b :: Constraint; type AllB c b = GAll 0 c (GAllRepB b); } baddDicts :: forall c f. (ConstraintsB b, AllB c b) => b f -> b (Dict c `Product` f) baddDicts :: forall c f. (ConstraintsB b, CanDeriveConstraintsB c b f, AllB c b) => b f -> b (Dict c `Product` f) -- | Similar to AllB but will put the functor argument f -- between the constraint c and the type a. For -- example: -- --
--   AllB  Show   Person ~ (Show    String,  Show    Int)
--   AllBF Show f Person ~ (Show (f String), Show (f Int))
--   
--   
type AllBF c f b = AllB (ClassF c f) b -- | Like bmap but a constraint is allowed to be required on each -- element of b -- -- E.g. If all fields of b are Showable then you could -- store each shown value in it's slot using Const: -- --
--   showFields :: (AllB Show b, ConstraintsB b) => b Identity -> b (Const String)
--   showFields = bmapC @Show showField
--     where
--       showField :: forall a. Show a => Identity a -> Const String a
--       showField (Identity a) = Const (show a)
--   
bmapC :: forall c b f g. (AllB c b, ConstraintsB b) => (forall a. c a => f a -> g a) -> b f -> b g -- | Like btraverse but with a constraint on the elements of -- b. btraverseC :: forall c b f g e. (TraversableB b, ConstraintsB b, AllB c b, Applicative e) => (forall a. c a => f a -> e (g a)) -> b f -> e (b g) class (ConstraintsB b, ProductB b) => ProductBC (b :: (k -> Type) -> Type) bdicts :: (ProductBC b, AllB c b) => b (Dict c) bdicts :: (ProductBC b, CanDeriveProductBC c b, AllB c b) => b (Dict c) type CanDeriveProductBC c b = (GenericN (b (Dict c)), AllB c b ~ GAll 0 c (GAllRepB b), GProductBC c (GAllRepB b) (RepN (b (Dict c)))) -- | Deprecated: Use bpureC instead buniqC :: forall c f b. (AllB c b, ProductBC b) => (forall a. c a => f a) -> b f -- | Builds a b f, by applying mempty on every field of -- b. bmempty :: forall f b. (AllBF Monoid f b, ConstraintsB b, ApplicativeB b) => b f -- | A wrapper for Barbie-types, providing useful instances. newtype Barbie (b :: (k -> Type) -> Type) f Barbie :: b f -> Barbie f [getBarbie] :: Barbie f -> b f -- | Uninhabited barbie type. data Void (f :: k -> Type) -- | A barbie type without structure. data Unit (f :: k -> Type) Unit :: Unit newtype Rec (p :: Type) a x Rec :: K1 R a x -> Rec a x [unRec] :: Rec a x -> K1 R a x class GProductB (f :: k -> *) (g :: k -> *) repbf repbg repbfg gbprod :: GProductB f g repbf repbg repbfg => Proxy f -> Proxy g -> repbf x -> repbg x -> repbfg x gbuniq :: (GProductB f g repbf repbg repbfg, f ~ g, repbf ~ repbg) => Proxy f -> Proxy repbf -> Proxy repbfg -> (forall a. f a) -> repbf x class GProductBC c repbx repbd gbdicts :: (GProductBC c repbx repbd, GAll 0 c repbx) => repbd x -- | 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 /* module Barbies.Bi -- | Map over both arguments at the same time. btmap :: (FunctorB (b f), FunctorT b) => (forall a. f a -> f' a) -> (forall a. g a -> g' a) -> b f g -> b f' g' -- | A version of btmap specialized to a single argument. btmap1 :: (FunctorB (b f), FunctorT b) => (forall a. f a -> g a) -> b f f -> b g g -- | Traverse over both arguments, first over f, then over -- g.. bttraverse :: (TraversableB (b f), TraversableT b, Monad t) => (forall a. f a -> t (f' a)) -> (forall a. g a -> t (g' a)) -> b f g -> t (b f' g') -- | A version of bttraverse specialized to a single argument. bttraverse1 :: (TraversableB (b f), TraversableT b, Monad t) => (forall a. f a -> t (g a)) -> b f f -> t (b g g) -- | Conceptually, this is like simultaneously using bpure and -- tpure. btpure :: (ApplicativeB (b Unit), FunctorT b) => (forall a. f a) -> (forall a. g a) -> b f g -- | A version of btpure specialized to a single argument. btpure1 :: (ApplicativeB (b Unit), FunctorT b) => (forall a. f a) -> b f f -- | Simultaneous product on both arguments. btprod :: (ApplicativeB (b (Alt (Product f f'))), FunctorT b, Alternative f, Alternative f') => b f g -> b f' g' -> b (f `Product` f') (g `Product` g') -- | Convert a FunctorB into a FunctorT and vice-versa. newtype Flip b l r Flip :: b r l -> Flip b l r [runFlip] :: Flip b l r -> b r l instance forall k1 k2 (b :: k2 -> k1 -> *) (l :: k1) (r :: k2). GHC.Show.Show (b r l) => GHC.Show.Show (Barbies.Bi.Flip b l r) instance forall k1 k2 (b :: k2 -> k1 -> *) (l :: k1) (r :: k2). GHC.Read.Read (b r l) => GHC.Read.Read (Barbies.Bi.Flip b l r) 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.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 (b :: (* -> *) -> k -> *) (f :: k). Barbies.Internal.DistributiveT.DistributiveT b => Barbies.Internal.DistributiveB.DistributiveB (Barbies.Bi.Flip b f) 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 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.FunctorB.FunctorB (b f)) => Barbies.Internal.FunctorT.FunctorT (Barbies.Bi.Flip b) instance forall i (b :: i -> (* -> *) -> *). (forall (f :: i). Barbies.Internal.DistributiveB.DistributiveB (b f)) => Barbies.Internal.DistributiveT.DistributiveT (Barbies.Bi.Flip b) instance forall k' k (b :: k' -> (k -> *) -> *). (forall (f :: k'). Barbies.Internal.TraversableB.TraversableB (b f)) => Barbies.Internal.TraversableT.TraversableT (Barbies.Bi.Flip b) instance forall k' k (b :: k' -> (k -> *) -> *). (forall (f :: k'). Barbies.Internal.ApplicativeB.ApplicativeB (b f)) => Barbies.Internal.ApplicativeT.ApplicativeT (Barbies.Bi.Flip b) -- | A common Haskell idiom is to parameterise a datatype by a functor or -- GADT (or any "indexed type" k -> Type), a pattern -- sometimes called HKD). This parameter acts like the outfit of a -- Barbie, turning it into a different doll. The canonical example would -- be: -- --
--   data Person f
--     = Person
--         { name :: f String
--         , age  :: f Int
--         }
--   
-- -- Let's say that we are writing an application where Person -- 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: -- --
--   Person (Const String)  -- for the raw input from the web-form,
--   Person (Either String) -- for the result of parsing and validating,
--   Person Identity        -- for the actual data,
--   Person DbColumn        -- To describe how to read / write a Person to the db
--   
--   data DbColumn a
--     = DbColumn
--         { colName :: String
--         , fromDb  :: DbDataParser a
--         , toDb    :: a -> DbData
--         }
--   
-- -- In such application it is likely that one will have lots of types like -- Person 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 Functor, Applicative or -- Traversable. For example, instead of writing an ad-hoc function -- that checks that all fields have a correct value, like -- --
--   checkPerson :: Person (Either String) -> Either [String] (Person Identity)
--   
-- -- we can write only one such function: -- --
--   check :: TraversableB b => b (Either String) -> Either [String] (b Identity)
--   check be
--     = case btraverse (either (const Nothing) (Just . Identity)) be of
--         Just bi -> Right bi
--         Nothing -> Left (bfoldMap (either (:[]) (const [])) be)
--   
-- -- Moreover, these classes come with default instances based on -- Generic, so using them is as easy as: -- --
--   data Person f
--     = Person
--         { name :: f String
--         , age  :: f Int
--         }
--     deriving
--       ( Generic
--       , FunctorB, TraversableB, ApplicativeB, ConstraintsB
--       )
--   
--   deriving instance AllBF Show f Person => Show (Person f)
--   deriving instance AllBF Eq   f Person => Eq   (Person f)
--   
module Barbies -- | Wrapper for barbies that act as containers of a by wearing -- (Const a). newtype Container b a Container :: b (Const a) -> Container b a [getContainer] :: Container b a -> b (Const a) -- | Wrapper for barbies that act as containers of e by wearing -- Either e. newtype ErrorContainer b e ErrorContainer :: b (Either e) -> ErrorContainer b e [getErrorContainer] :: ErrorContainer b e -> b (Either e) -- | A wrapper for Barbie-types, providing useful instances. newtype Barbie (b :: (k -> Type) -> Type) f Barbie :: b f -> Barbie f [getBarbie] :: Barbie f -> b f -- | Uninhabited barbie type. data Void (f :: k -> Type) -- | A barbie type without structure. data Unit (f :: k -> Type) Unit :: Unit -- | Support for operating on Barbie-types with constrained functions. module Barbies.Constraints -- | Dict c a is evidence that there exists an instance of -- c a. -- -- It is essentially equivalent to Dict (c a) from the -- constraints package, but because of its kind, it allows us to -- define things like Dict Show. data Dict c a [Dict] :: c a => Dict c a -- | Turn a constrained-function into an unconstrained one that uses the -- packed instance dictionary instead. requiringDict :: (c a => r) -> Dict c a -> r -- | Similar to AllB but will put the functor argument f -- between the constraint c and the type a. For -- example: -- --
--   AllB  Show   Person ~ (Show    String,  Show    Int)
--   AllBF Show f Person ~ (Show (f String), Show (f Int))
--   
--   
type AllBF c f b = AllB (ClassF c f) b -- | ClassF has one universal instance that makes ClassF -- c f a equivalent to c (f a). However, we have -- --
--   'ClassF c f :: k -> Constraint
--   
-- -- This is useful since it allows to define constraint-constructors like -- ClassF Monoid Maybe class c (f a) => ClassF c f a -- | Like ClassF but for binary relations. class c (f a) (g a) => ClassFG c f g a module Barbies.Internal -- | Default implementation of bmap based on Generic. gbmapDefault :: CanDeriveFunctorB b f g => (forall a. f a -> g a) -> b f -> b g class GFunctor (n :: Nat) f g repbf repbg gmap :: GFunctor n f g repbf repbg => Proxy n -> (forall a. f a -> g a) -> repbf x -> repbg x -- | CanDeriveFunctorB B f g is in practice a predicate -- about B only. Intuitively, it says that the following holds, -- for any arbitrary f: -- -- type CanDeriveFunctorB b f g = (GenericP 0 (b f), GenericP 0 (b g), GFunctor 0 f g (RepP 0 (b f)) (RepP 0 (b g))) -- | CanDeriveFunctorT T f g x is in practice a predicate -- about T only. Intuitively, it says that the following holds, -- for any arbitrary f: -- -- type CanDeriveFunctorT t f g x = (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 btraverse based on Generic. gbtraverseDefault :: forall b f g e. (Applicative e, CanDeriveTraversableB b f g) => (forall a. f a -> e (g a)) -> b f -> e (b g) class GTraversable n f g repbf repbg gtraverse :: (GTraversable n f g repbf repbg, Applicative t) => Proxy n -> (forall a. f a -> t (g a)) -> repbf x -> t (repbg x) -- | CanDeriveTraversableB B f g is in practice a predicate -- about B only. It is analogous to CanDeriveFunctorB, so -- it essentially requires the following to hold, for any arbitrary -- f: -- -- type CanDeriveTraversableB b f g = (GenericP 0 (b f), GenericP 0 (b g), GTraversable 0 f g (RepP 0 (b f)) (RepP 0 (b g))) -- | CanDeriveTraversableT T f g x is in practice a -- predicate about T only. It is analogous to -- CanDeriveFunctorT, so it essentially requires the following to -- hold, for any arbitrary f: -- -- type CanDeriveTraversableT t f g x = (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 bdistribute based on Generic. gbdistributeDefault :: CanDeriveDistributiveB b f g => Functor f => f (b g) -> b (Compose f g) class (Functor f) => GDistributive (n :: Nat) f repbg repbfg gdistribute :: GDistributive n f repbg repbfg => Proxy n -> f (repbg x) -> repbfg x -- | CanDeriveDistributiveB B f g is in practice a -- predicate about B only. Intuitively, it says the the -- following holds for any arbitrary f: -- -- type CanDeriveDistributiveB b f g = (GenericP 0 (b g), GenericP 0 (b (Compose f g)), GDistributive 0 f (RepP 0 (b g)) (RepP 0 (b (Compose f g)))) -- | CanDeriveDistributiveT T f g x is in practice a -- predicate about T only. Intuitively, it says the the -- following holds for any arbitrary f: -- -- type CanDeriveDistributiveT (t :: (Type -> Type) -> i -> Type) f g x = (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 :: forall b f. CanDeriveApplicativeB b f f => (forall a. f a) -> b f -- | Default implementation of bprod based on Generic. gbprodDefault :: forall b f g. CanDeriveApplicativeB b f g => b f -> b g -> b (f `Product` g) class GApplicative n (f :: k -> *) (g :: k -> *) repbf repbg repbfg gprod :: GApplicative n f g repbf repbg repbfg => Proxy n -> Proxy f -> Proxy g -> repbf x -> repbg x -> repbfg x gpure :: (GApplicative n f g repbf repbg repbfg, f ~ g, repbf ~ repbg) => Proxy n -> Proxy f -> Proxy repbf -> Proxy repbfg -> (forall a. f a) -> repbf x -- | CanDeriveApplicativeB B f g is in practice a predicate -- about B only. Intuitively, it says that the following holds, -- for any arbitrary f: -- -- type CanDeriveApplicativeB b f g = (GenericP 0 (b f), GenericP 0 (b g), GenericP 0 (b (f `Product` g)), GApplicative 0 f g (RepP 0 (b f)) (RepP 0 (b g)) (RepP 0 (b (f `Product` g)))) -- | CanDeriveApplicativeT T f g x is in practice a -- predicate about T only. Intuitively, it says that the -- following holds, for any arbitrary f: -- -- type CanDeriveApplicativeT t f g x = (GenericP 1 (t f x), GenericP 1 (t g x), GenericP 1 (t (f `Product` g) x), GApplicative 1 f g (RepP 1 (t f x)) (RepP 1 (t g x)) (RepP 1 (t (f `Product` g) x))) -- | Default implementation of baddDicts based on Generic. gbaddDictsDefault :: forall b c f. (CanDeriveConstraintsB c b f, AllB c b) => b f -> b (Dict c `Product` f) class GConstraints n c f repbx repbf repbdf gaddDicts :: (GConstraints n c f repbx repbf repbdf, GAll n c repbx) => repbf x -> repbdf x -- | CanDeriveConstraintsB B f g is in practice a predicate -- about B only. Intuitively, it says that the following holds, -- for any arbitrary f: -- -- type CanDeriveConstraintsB c b f = (GenericP 0 (b f), GenericP 0 (b (Dict c `Product` f)), AllB c b ~ GAll 0 c (GAllRepB b), GConstraints 0 c f (GAllRepB b) (RepP 0 (b f)) (RepP 0 (b (Dict c `Product` f)))) -- | CanDeriveConstraintsT T f g x is in practice a -- predicate about T only. Intuitively, it says that the -- following holds, for any arbitrary f and x: -- -- type CanDeriveConstraintsT c t f x = (GenericP 1 (t f x), GenericP 1 (t (Dict c `Product` f) x), AllT c t ~ GAll 1 c (GAllRepT t), GConstraints 1 c f (GAllRepT t) (RepP 1 (t f x)) (RepP 1 (t (Dict c `Product` f) x))) type family GAll (n :: Nat) (c :: k -> Constraint) (repbf :: Type -> Type) :: Constraint -- | The representation used for the generic computation of the -- AllB c b constraints. Here X is an arbitrary -- constant since the actual argument to b is irrelevant. type GAllRepB b = TagSelf 0 b (RepN (b X)) -- | The representation used for the generic computation of the -- AllT c t constraints. Here X and Y are -- arbitrary constants since the actual argument to t is -- irrelevant. type GAllRepT t = TagSelf 1 t (RepN (t X Y)) data X a data family Y :: k -- | We use the type-families to generically compute AllB c -- b. Intuitively, if b' f occurs inside b f, then -- we should just add AllB b' c to AllB b -- c. The problem is that if b is a recursive type, and -- b' is b, then ghc will choke and blow the stack -- (instead of computing a fixpoint). -- -- So, we would like to behave differently when b = b' and add -- () instead of AllB b f to break the -- recursion. Our trick will be to use a type family to inspect -- RepN (b f) and distinguish recursive usages from -- non-recursive ones, tagging them with different types, so we can -- distinguish them in the instances. type TagSelf n b repbf = TagSelf' n b (Indexed b (n + 1)) repbf type family TagSelf' (n :: Nat) (b :: kb) (b' :: kb) (repbf :: * -> *) :: * -> * data family Self (b :: k -> k') :: k -> k' data family Other (b :: k -> k') :: k -> k' -- | Default implementation of bstrip based on Generic. gbcoverDefault :: CanDeriveBareB b => b Bare Identity -> b Covered Identity -- | Default implementation of bstrip based on Generic. gbstripDefault :: CanDeriveBareB b => b Covered Identity -> b Bare Identity class GBare (n :: Nat) repbi repbb gstrip :: GBare n repbi repbb => Proxy n -> repbi x -> repbb x gcover :: GBare n repbi repbb => Proxy n -> repbb x -> repbi x -- | All types that admit a generic FunctorB instance, and have all -- their occurrences of f under a Wear admit a generic -- BareB instance. type CanDeriveBareB b = (GenericP 0 (b Bare Identity), GenericP 0 (b Covered Identity), GBare 0 (RepP 0 (b Covered Identity)) (RepP 0 (b Bare Identity))) 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 newtype Rec (p :: Type) a x Rec :: K1 R a x -> Rec a x [unRec] :: Rec a x -> K1 R a x class (Coercible (Rep a) (RepN a), Generic a) => GenericN (a :: Type) where { type family RepN (a :: Type) :: 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 class (Coercible (Rep a) (RepP n a), Generic a) => GenericP (n :: Nat) (a :: Type) where { type family RepP n a :: Type -> Type; type RepP n 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