Options that further configure how the functions in Data.Functor.Classes.Generic should behave.
Moduletransformers-compat-0.7.2Haskell2010
Data.Functor.Classes.Generic
Functions to generically derive C.Eq1, C.Ord1, C.Read1, and C.Show1
instances from Data.Functor.Classes.
- 2 types
- 10 values
- Packagetransformers-compat-0.7.2
- Exports12
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceGeneric.hs
Options
3 declarationsOptions that match the behavior of the installed version of GHC.
Options that match the behavior of the most recent GHC release.
Eq1
2 declarationsLike liftEqDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).
Ord1
2 declarationsA sensible default liftCompare implementation for Generic1 instances.
Like liftCompareDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).
Read1
2 declarationsA sensible default liftReadsPrec implementation for Generic1 instances.
Like liftReadsPrecDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).
Show1
2 declarationsA sensible default liftShowsPrec implementation for Generic1 instances.
Like liftShowsPrecDefault, but with configurable Options.
GenericFunctorClasses
1 declarationAn adapter newtype, suitable for DerivingVia. Its Eq1, Ord1,
Read1, and Show1 instances leverage Generic1-based defaults.
Constructors
Instances8Eq1, Ord1, Read1, Show1, Eq, Ord, …
(GEq1 NonV4 (Rep1 f), Generic1 f) => Eq1 (FunctorClassesDefault f)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GOrd1 NonV4 (Rep1 f), Generic1 f) => Ord1 (FunctorClassesDefault f)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GRead1 NonV4 (Rep1 f), Generic1 f) => Read1 (FunctorClassesDefault f)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GShow1 NonV4 (Rep1 f), Generic1 f) => Show1 (FunctorClassesDefault f)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GEq (Rep1 f a), Generic1 f) => Eq (FunctorClassesDefault f a)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GOrd (Rep1 f a), Generic1 f) => Ord (FunctorClassesDefault f a)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GRead (Rep1 f a), Generic1 f) => Read (FunctorClassesDefault f a)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal(GShow (Rep1 f a), Generic1 f) => Show (FunctorClassesDefault f a)Defined in transformers-compat-0.7.2 · Data.Functor.Classes.Generic.Internal
Example
0 declarationsThe most straightforward way to use the defaults in this module is to use
DerivingVia on GHC 8.6 or later. For example:
{-# LANGUAGE DeriveGeneric, DerivingVia #-}
import Data.Functor.Classes
import Data.Functor.Classes.Generic
import GHC.Generics
data Pair a = Pair a a
deriving stock Generic1
deriving (Eq1, Ord1, Read1, Show1)
via FunctorClassesDefault Pair
If using an older version of GHC, then one can also define instances manually.
This is slightly trickier to accomplish since this module exports different
functions depending on which version of transformers this library is built
against. Here is an example of how to define instances manually:
{-# LANGUAGE CPP, DeriveGeneric #-}
import Data.Functor.Classes
import Data.Functor.Classes.Generic
import GHC.Generics
data Pair a = Pair a a deriving Generic1
instance C.Eq1 Pair where
#if MIN_VERSION_transformers(0,4,0) && !(MIN_VERSION_transformers(0,5,0))
C.eq1 = eq1Default
#else
C.liftEq = liftEqDefault
#endif
instance C.Ord1 Pair where
#if MIN_VERSION_transformers(0,4,0) && !(MIN_VERSION_transformers(0,5,0))
C.compare1 = compare1Default
#else
C.liftCompare = liftCompareDefault
#endif
instance C.Read1 Pair where
#if MIN_VERSION_transformers(0,4,0) && !(MIN_VERSION_transformers(0,5,0))
C.readsPrec1 = readsPrec1Default
#else
C.liftReadsPrec = liftReadsPrecDefault
#endif
instance C.Show1 Pair where
#if MIN_VERSION_transformers(0,4,0) && !(MIN_VERSION_transformers(0,5,0))
C.showsPrec1 = showsPrec1Default
#else
C.liftShowsPrec = liftShowsPrecDefault
#endif