HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Moduletransformers-compat-0.8Haskell2010

Data.Functor.Classes.Generic

Functions to generically derive C.Eq1, C.Ord1, C.Read1, and C.Show1 instances from Data.Functor.Classes.

Contents
  1. Options
  2. Eq1
  3. Ord1
  4. Read1
  5. Show1
  6. GenericFunctorClasses
  7. Example
Synopsis

Options

Eq1

Ord1

Read1

Show1

GenericFunctorClasses

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

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. Here is an example:

{-# LANGUAGE 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
    C.liftEq = liftEqDefault

instance C.Ord1 Pair where
    C.liftCompare = liftCompareDefault

instance C.Read1 Pair where
    C.liftReadsPrec = liftReadsPrecDefault

instance C.Show1 Pair where
    C.liftShowsPrec = liftShowsPrecDefault