Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Generics.Traversable.Generic
Contents
Description
For a datatype where every subterm is interesting, it is
possible to leverage Generic
to automatically produce the
GTraversable
instance.
This module defines a default GTraversable
instance for most
Generic
types, though you can override it with a custom instance
if you so wish. The gtraverse
implementation for this instance
traverses every subterm, and traverses left-to-right on products
:*:
.
Example usage:
{-# LANGUAGE FlexibleInstances, DeriveGeneric #-} import Data.Maybe (isJust) data MyConfig = MyConfig { firstKey :: Maybe Int , secondKey :: Maybe String , thirdKey :: Maybe Bool } deriving (Generic) class SettableConfigKey a where isSet :: a -> Bool instance SettableConfigKey (Maybe a) where isSet = isJust isAnyConfigKeySet :: MyConfig -> Bool isAnyConfigKeySet = gfoldr @SettableConfigKey ((||) . isSet)
For Generic
types that have Rec1
in their representation, this
module will not work for GHC versions below 8.6.1, as the instance
makes use of QuantifiedConstraints
. Instead, the instance for
Rec1
will cause a type error.
Synopsis
- class GTraversable' c (f :: * -> *) where
- gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. f p -> g (f p)
Documentation
class GTraversable' c (f :: * -> *) where Source #
Special version of GTraversable
for the representation types
from Generic
.
Methods
gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. f p -> g (f p) Source #
Instances
GTraversable' c Par1 Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. Par1 p -> g (Par1 p) Source # | |
GTraversable' c (V1 :: Type -> Type) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. V1 p -> g (V1 p) Source # | |
GTraversable' c (U1 :: Type -> Type) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. U1 p -> g (U1 p) Source # | |
(forall p. GTraversable c (f p)) => GTraversable' c (Rec1 f) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. Rec1 f p -> g (Rec1 f p) Source # | |
(GTraversable' c f, GTraversable' c g) => GTraversable' c (f :*: g) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g0 => (forall d. c d => d -> g0 d) -> forall p. (f :*: g) p -> g0 ((f :*: g) p) Source # | |
(GTraversable' c f, GTraversable' c g) => GTraversable' c (f :+: g) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g0 => (forall d. c d => d -> g0 d) -> forall p. (f :+: g) p -> g0 ((f :+: g) p) Source # | |
c con => GTraversable' c (K1 i con :: Type -> Type) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. K1 i con p -> g (K1 i con p) Source # | |
(Traversable f, GTraversable' c g) => GTraversable' c (f :.: g) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g0 => (forall d. c d => d -> g0 d) -> forall p. (f :.: g) p -> g0 ((f :.: g) p) Source # | |
GTraversable' c f => GTraversable' c (M1 i meta f) Source # | |
Defined in Data.Generics.Traversable.Generic Methods gtraverse' :: Applicative g => (forall d. c d => d -> g d) -> forall p. M1 i meta f p -> g (M1 i meta f p) Source # |
Orphan instances
(Generic a, GTraversable' c (Rep a)) => GTraversable c a Source # | |
Methods gtraverse :: Applicative f => (forall d. c d => d -> f d) -> a -> f a Source # |