HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

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

Options

3 declarations

Eq1

2 declarations

Ord1

2 declarations

Read1

2 declarations

Show1

2 declarations

GenericFunctorClasses

1 declaration
newtypenewtype FunctorClassesDefault (f :: Type -> Type) a
#

An adapter newtype, suitable for DerivingVia. Its Eq1, Ord1, Read1, and Show1 instances leverage Generic1-based defaults.

Instances8Eq1, Ord1, Read1, Show1, Eq, Ord, …

Example

0 declarations

The 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