generic-data-0.9.2.1: Deriving instances with GHC.Generics and related utilities
Safe HaskellSafe-Inferred
LanguageHaskell2010

Generic.Data.Internal.Traversable

Description

Generic implementation of Foldable and Traversable.

There is already a naive implementation using the generic Rep's own instances of Foldable and Traversable. However, deriving then generates a lot of code that may not be simplified away by GHC, that results in unnecessary run-time overhead.

In contrast, this implementation guarantees that the generated code is identical to stock-derived instances of Foldable and Traversable, which have the following syntactic properties:

  • constructors with zero fields use pure once;
  • constructors with one field use fmap once;
  • constructors with n >= 2 fields use liftA2 once and (<*>) n-2 times.

The heavy lifting is actually done by the ap-normalize library.

Synopsis

Library

gfoldMap :: (Generic1 f, GFoldable (Rep1 f), Monoid m) => (a -> m) -> f a -> m Source #

Generic foldMap.

instance Foldable MyTypeF where
  foldMap = gfoldMap

gtraverse :: (Generic1 f, GTraversable (Rep1 f), Applicative m) => (a -> m b) -> f a -> m (f b) Source #

Generic traverse.

instance Traversable MyTypeF where
  traverse = gtraverse

gsequenceA :: (Generic1 f, GTraversable (Rep1 f), Applicative m) => f (m a) -> m (f a) Source #

Generic sequenceA.

instance Traversable MyTypeF where
  sequenceA = gsequenceA

See also gtraverse.

class GFoldable_ t => GFoldable t Source #

Class of generic representations for which Foldable can be derived.

Instances

Instances details
GFoldable_ t => GFoldable t Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

class GTraversable_ t => GTraversable t Source #

Class of generic representations for which Traversable can be derived.

Instances

Instances details
GTraversable_ t => GTraversable t Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

class (GFoldMap t, Foldable t) => GFoldable_ t Source #

Internal definition of GFoldable.

Instances

Instances details
(GFoldMap t, Foldable t) => GFoldable_ t Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

class (GTraverse Kleisli t, GTraverse Equal t) => GTraversable_ t Source #

Internal definition of GTraversable.

Instances

Instances details
(GTraverse Kleisli t, GTraverse Equal t) => GTraversable_ t Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Foldable

data Maybe' m Source #

Isomorphic to Maybe m, but we need to micromanage the use of Monoid vs Semigroup to match exactly the output of stock deriving, for inspection testing.

Constructors

Nothing' 
Just' m 

type EndoM m = Endo (Maybe' m) Source #

liftEndoM :: Monoid m => m -> EndoM m Source #

lowerEndoM :: Monoid m => EndoM m -> m Source #

class GFoldMap t where Source #

Methods

gfoldMap_ :: Monoid m => (a -> m) -> t a -> EndoM m Source #

Instances

Instances details
GFoldMap Par1 Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> Par1 a -> EndoM m Source #

GFoldMap (V1 :: Type -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> V1 a -> EndoM m Source #

GFoldMap (U1 :: Type -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> U1 a -> EndoM m Source #

Foldable t => GFoldMap (Rec1 t) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> Rec1 t a -> EndoM m Source #

GFoldMap (K1 i a :: Type -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a0 -> m) -> K1 i a a0 -> EndoM m Source #

(GFoldMap f, GFoldMap g) => GFoldMap (f :+: g) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> (f :+: g) a -> EndoM m Source #

(GFoldMap f, GFoldMap g) => GFoldMap (f :*: g) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> (f :*: g) a -> EndoM m Source #

GFoldMap f => GFoldMap (M1 i c f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> M1 i c f a -> EndoM m Source #

(Foldable t, Foldable f) => GFoldMap (t :.: f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gfoldMap_ :: Monoid m => (a -> m) -> (t :.: f) a -> EndoM m Source #

Traversable

data Equal (f :: Type -> Type) a b where Source #

Constructors

Refl :: Equal f (f b) b 

Instances

Instances details
GTraverse Equal Par1 Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Equal f a b -> Par1 a -> Aps f (Par1 b) Source #

Traversable t => GTraverse Equal (Rec1 t) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Equal f a b -> Rec1 t a -> Aps f (Rec1 t b) Source #

(Traversable t, Traversable f) => GTraverse Equal (t :.: f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => Equal f0 a b -> (t :.: f) a -> Aps f0 ((t :.: f) b) Source #

newtype Kleisli f a b Source #

Constructors

Kleisli (a -> f b) 

Instances

Instances details
GTraverse Kleisli Par1 Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Kleisli f a b -> Par1 a -> Aps f (Par1 b) Source #

Traversable t => GTraverse Kleisli (Rec1 t) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Kleisli f a b -> Rec1 t a -> Aps f (Rec1 t b) Source #

(Traversable t, Traversable f) => GTraverse Kleisli (t :.: f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => Kleisli f0 a b -> (t :.: f) a -> Aps f0 ((t :.: f) b) Source #

class GTraverse arr t where Source #

Methods

gtraverse_ :: Applicative f => arr f a b -> t a -> Aps f (t b) Source #

Instances

Instances details
GTraverse Kleisli Par1 Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Kleisli f a b -> Par1 a -> Aps f (Par1 b) Source #

GTraverse Equal Par1 Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Equal f a b -> Par1 a -> Aps f (Par1 b) Source #

GTraverse arr (V1 :: Type -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => arr f a b -> V1 a -> Aps f (V1 b) Source #

GTraverse arr (U1 :: Type -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => arr f a b -> U1 a -> Aps f (U1 b) Source #

Traversable t => GTraverse Kleisli (Rec1 t) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Kleisli f a b -> Rec1 t a -> Aps f (Rec1 t b) Source #

Traversable t => GTraverse Equal (Rec1 t) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a b. Applicative f => Equal f a b -> Rec1 t a -> Aps f (Rec1 t b) Source #

GTraverse arr (K1 i a :: Type -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f :: Type -> Type) a0 b. Applicative f => arr f a0 b -> K1 i a a0 -> Aps f (K1 i a b) Source #

(GTraverse arr f, GTraverse arr g) => GTraverse arr (f :*: g) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => arr f0 a b -> (f :*: g) a -> Aps f0 ((f :*: g) b) Source #

(GTraverse arr f, GTraverse arr g) => GTraverse arr (f :+: g) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => arr f0 a b -> (f :+: g) a -> Aps f0 ((f :+: g) b) Source #

GTraverse arr f => GTraverse arr (M1 i c f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => arr f0 a b -> M1 i c f a -> Aps f0 (M1 i c f b) Source #

(Traversable t, Traversable f) => GTraverse Kleisli (t :.: f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => Kleisli f0 a b -> (t :.: f) a -> Aps f0 ((t :.: f) b) Source #

(Traversable t, Traversable f) => GTraverse Equal (t :.: f) Source # 
Instance details

Defined in Generic.Data.Internal.Traversable

Methods

gtraverse_ :: forall (f0 :: Type -> Type) a b. Applicative f0 => Equal f0 a b -> (t :.: f) a -> Aps f0 ((t :.: f) b) Source #