Safe Haskell | None |
---|---|
Language | Haskell2010 |
Generic combinators to derive type class instances.
base classes that GHC can not derive instances for, as of version 8.2:
Semigroup
,Monoid
,Applicative
,Alternative
,Eq1
,Ord1
,Show1
.
On base < 4.12 (i.e., GHC < 8.6), import Generic.Data.Orphans to obtain instances needed internally to derive those.
GHC can derive instances for other classes here, although there may be types supported by one method but not the other or vice versa.
- gmappend :: (Generic a, Semigroup (Rep a ())) => a -> a -> a
- gmempty :: (Generic a, Monoid (Rep a ())) => a
- gmappend' :: (Generic a, Monoid (Rep a ())) => a -> a -> a
- geq :: (Generic a, Eq (Rep a ())) => a -> a -> Bool
- gcompare :: (Generic a, Ord (Rep a ())) => a -> a -> Ordering
- gshowsPrec :: (Generic a, GShow0 (Rep a)) => Int -> a -> ShowS
- type GShow0 = GShow Proxy
- gfromEnum :: (Generic a, GEnum (Rep a)) => a -> Int
- gtoEnum :: forall a. (Generic a, GEnum (Rep a)) => Int -> a
- class GEnum f
- gminBound :: (Generic a, GBounded (Rep a)) => a
- gmaxBound :: (Generic a, GBounded (Rep a)) => a
- class GBounded f
- gfmap :: (Generic1 f, Functor (Rep1 f)) => (a -> b) -> f a -> f b
- gconstmap :: (Generic1 f, Functor (Rep1 f)) => a -> f b -> f a
- gfoldMap :: (Generic1 f, Foldable (Rep1 f), Monoid m) => (a -> m) -> f a -> m
- gfoldr :: (Generic1 f, Foldable (Rep1 f)) => (a -> b -> b) -> b -> f a -> b
- gtraverse :: (Generic1 f, Traversable (Rep1 f), Applicative m) => (a -> m b) -> f a -> m (f b)
- gsequenceA :: (Generic1 f, Traversable (Rep1 f), Applicative m) => f (m a) -> m (f a)
- gpure :: (Generic1 f, Applicative (Rep1 f)) => a -> f a
- gap :: (Generic1 f, Applicative (Rep1 f)) => f (a -> b) -> f a -> f b
- gliftA2 :: (Generic1 f, Applicative (Rep1 f)) => (a -> b -> c) -> f a -> f b -> f c
- gempty :: (Generic1 f, Alternative (Rep1 f)) => f a
- galt :: (Generic1 f, Alternative (Rep1 f)) => f a -> f a -> f a
- gliftEq :: (Generic1 f, Eq1 (Rep1 f)) => (a -> b -> Bool) -> f a -> f b -> Bool
- gliftCompare :: (Generic1 f, Ord1 (Rep1 f)) => (a -> b -> Ordering) -> f a -> f b -> Ordering
- gliftShowsPrec :: (Generic1 f, GShow1 (Rep1 f)) => (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
- type GShow1 = GShow Identity
- newtype Id1 f a = Id1 {
- unId1 :: f a
- newtype Opaque a = Opaque {
- unOpaque :: a
- newtype Opaque1 f a = Opaque1 {
- unOpaque1 :: f a
- newtype Generically a = Generically {
- unGenerically :: a
- newtype Generically1 f a = Generically1 {
- unGenerically1 :: f a
- gdatatypeName :: forall a. (Generic a, GDatatype (Rep a)) => String
- gmoduleName :: forall a. (Generic a, GDatatype (Rep a)) => String
- gpackageName :: forall a. (Generic a, GDatatype (Rep a)) => String
- gisNewtype :: forall a. (Generic a, GDatatype (Rep a)) => Bool
- class GDatatype f
- gconName :: forall a. Constructors a => a -> String
- gconFixity :: forall a. Constructors a => a -> Fixity
- gconIsRecord :: forall a. Constructors a => a -> Bool
- gconNum :: forall a. Constructors a => Int
- class (Generic a, GConstructors (Rep a)) => Constructors a
- class GConstructors r
Regular classes
Semigroup
Monoid
Eq
Can also be derived by GHC as part of the standard.
Ord
Can also be derived by GHC as part of the standard.
Show
Can also be derived by GHC as part of the standard.
gshowsPrec :: (Generic a, GShow0 (Rep a)) => Int -> a -> ShowS Source #
Generic showsPrec
.
instanceShow
MyType whereshowsPrec
=gshowsPrec
Enum
Can also be derived by GHC as part of the standard.
Generic representation of Enum
types.
Bounded
Can also be derived by GHC as part of the standard.
Generic representation of Bounded
types.
Higher-kinded classes
Functor
Can also be derived by GHC (DeriveFunctor
extension).
Foldable
Can also be derived by GHC (DeriveFoldable
extension).
Traversable
Can also be derived by GHC (DeriveTraversable
extension).
gtraverse :: (Generic1 f, Traversable (Rep1 f), Applicative m) => (a -> m b) -> f a -> m (f b) Source #
Generic traverse
.
instanceTraversable
MyTypeF wheretraverse
=gtraverse
gsequenceA :: (Generic1 f, Traversable (Rep1 f), Applicative m) => f (m a) -> m (f a) Source #
Applicative
Alternative
Eq1
gliftEq :: (Generic1 f, Eq1 (Rep1 f)) => (a -> b -> Bool) -> f a -> f b -> Bool Source #
Generic liftEq
.
Ord1
gliftCompare :: (Generic1 f, Ord1 (Rep1 f)) => (a -> b -> Ordering) -> f a -> f b -> Ordering Source #
Generic liftCompare
.
Show1
gliftShowsPrec :: (Generic1 f, GShow1 (Rep1 f)) => (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS Source #
Fields wrappers for deriving
A newtype whose instances for simple classes (Eq
, Ord
, Read
, Show
)
use higher-kinded class instances for f
(Eq1
, Ord1
, Read1
, Show1
).
Eq1 f => Eq1 (Id1 f) Source # | |
Ord1 f => Ord1 (Id1 f) Source # | |
Read1 f => Read1 (Id1 f) Source # | |
Show1 f => Show1 (Id1 f) Source # | |
(Eq1 f, Eq a) => Eq (Id1 f a) Source # | |
(Ord1 f, Ord a) => Ord (Id1 f a) Source # | |
(Read1 f, Read a) => Read (Id1 f a) Source # | |
(Show1 f, Show a) => Show (Id1 f a) Source # | |
A newtype with trivial instances, that considers
every value equivalent to every other one,
and shows as just "_"
.
A higher-kinded version of Opaque
.
Newtypes
newtype Generically a Source #
Type with instances derived via Generic
.
Generically | |
|
(Generic a, GBounded (Rep a)) => Bounded (Generically a) Source # | |
(Generic a, GEnum (Rep a)) => Enum (Generically a) Source # | |
(Generic a, Eq (Rep a ())) => Eq (Generically a) Source # | |
(Generic a, Ord (Rep a ())) => Ord (Generically a) Source # | |
(Generic a, GShow0 (Rep a)) => Show (Generically a) Source # | |
Generic a => Generic (Generically a) Source # | |
(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a) Source # | |
(Generic a, Monoid (Rep a ())) => Monoid (Generically a) Source # | |
type Rep (Generically a) Source # | |
newtype Generically1 f a Source #
Type with instances derived via Generic1
.
Generically1 | |
|
(Generic1 * f, Functor (Rep1 * f)) => Functor (Generically1 f) Source # | |
(Generic1 * f, Applicative (Rep1 * f)) => Applicative (Generically1 f) Source # | |
(Generic1 * f, Foldable (Rep1 * f)) => Foldable (Generically1 f) Source # | |
(Generic1 * f, Traversable (Rep1 * f)) => Traversable (Generically1 f) Source # | |
(Generic1 * f, Eq1 (Rep1 * f)) => Eq1 (Generically1 f) Source # | |
(Generic1 * f, Ord1 (Rep1 * f)) => Ord1 (Generically1 f) Source # | |
(Generic1 * f, GShow1 (Rep1 * f)) => Show1 (Generically1 f) Source # | |
(Generic1 * f, Alternative (Rep1 * f)) => Alternative (Generically1 f) Source # | |
Generic1 * f => Generic1 * (Generically1 f) Source # | |
(Generic1 * f, Eq1 (Rep1 * f), Eq a) => Eq (Generically1 f a) Source # | |
(Generic1 * f, Ord1 (Rep1 * f), Ord a) => Ord (Generically1 f a) Source # | |
(Generic1 * f, GShow1 (Rep1 * f), Show a) => Show (Generically1 f a) Source # | |
Generic (f a) => Generic (Generically1 f a) Source # | |
type Rep1 * (Generically1 f) Source # | |
type Rep (Generically1 f a) Source # | |
Accessing metadata
Using TypeApplications
.
Datatype
gdatatypeName :: forall a. (Generic a, GDatatype (Rep a)) => String Source #
Name of the first data constructor in a type as a string.
gdatatypeName
@(Maybe
AnyType) = "Maybe"
gmoduleName :: forall a. (Generic a, GDatatype (Rep a)) => String Source #
Name of the module where the first type constructor is defined.
gmoduleName
@(Maybe
AnyType) = "GHC.Base"
gpackageName :: forall a. (Generic a, GDatatype (Rep a)) => String Source #
Name of the package where the first type constructor is defined.
gpackageName
@(Maybe
AnyType) = "base"
gisNewtype :: forall a. (Generic a, GDatatype (Rep a)) => Bool Source #
True
if the first type constructor is a newtype.
Generic representations that contain datatype metadata.
Constructor
gconName :: forall a. Constructors a => a -> String Source #
gconFixity :: forall a. Constructors a => a -> Fixity Source #
The fixity of the first constructor.
gconFixity
(Just
0) =Prefix
gconFixity
([] :*: id) =Infix
RightAssociative
6
gconIsRecord :: forall a. Constructors a => a -> Bool Source #
True
if the constructor is a record.
gconIsRecord
(Just
0) =False
gconIsRecord
(Sum
0) =True
-- newtypeSum
a = Sum { getSum :: a }
gconNum :: forall a. Constructors a => Int Source #
class (Generic a, GConstructors (Rep a)) => Constructors a Source #
Constraint synonym for Generic
and GConstructor
.
(Generic a, GConstructors * (Rep a)) => Constructors a Source # | |
class GConstructors r Source #
Generic representations that contain constructor metadata.
(GConstructors k f, GConstructors k g) => GConstructors k ((:+:) k f g) Source # | |
Constructor Meta c => GConstructors k (M1 k C c f) Source # | |
GConstructors k f => GConstructors k (M1 k D c f) Source # | |