transformers-compat
Copyright(C) 2015-2016 Edward Kmett Ryan Scott
LicenseBSD-style (see the file LICENSE)
MaintainerRyan Scott
StabilityProvisional
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Data.Functor.Classes.Generic

Description

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

Synopsis

Options

data Options Source #

Options that further configure how the functions in Data.Functor.Classes.Generic should behave. Currently, the Options have no effect (but this may change in the future).

Constructors

Options 

defaultOptions :: Options Source #

Options that match the behavior of the installed version of GHC.

latestGHCOptions :: Options Source #

Options that match the behavior of the most recent GHC release.

Eq1

liftEqDefault :: (GEq1 (Rep1 f), Generic1 f) => (a -> b -> Bool) -> f a -> f b -> Bool Source #

A sensible default liftEq implementation for Generic1 instances.

liftEqOptions :: (GEq1 (Rep1 f), Generic1 f) => Options -> (a -> b -> Bool) -> f a -> f b -> Bool Source #

Like liftEqDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).

Ord1

liftCompareDefault :: (GOrd1 (Rep1 f), Generic1 f) => (a -> b -> Ordering) -> f a -> f b -> Ordering Source #

A sensible default liftCompare implementation for Generic1 instances.

liftCompareOptions :: (GOrd1 (Rep1 f), Generic1 f) => Options -> (a -> b -> Ordering) -> f a -> f b -> Ordering Source #

Like liftCompareDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).

Read1

liftReadsPrecDefault :: (GRead1 (Rep1 f), Generic1 f) => (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a) Source #

A sensible default liftReadsPrec implementation for Generic1 instances.

liftReadsPrecOptions :: (GRead1 (Rep1 f), Generic1 f) => Options -> (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a) Source #

Like liftReadsPrecDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).

Show1

liftShowsPrecDefault :: (GShow1 (Rep1 f), Generic1 f) => (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS Source #

A sensible default liftShowsPrec implementation for Generic1 instances.

liftShowsPrecOptions :: (GShow1 (Rep1 f), Generic1 f) => Options -> (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS Source #

Like liftShowsPrecDefault, but with configurable Options. Currently, the Options have no effect (but this may change in the future).

GenericFunctorClasses

newtype FunctorClassesDefault (f :: Type -> Type) a Source #

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

Instances

Instances details
(GEq1 (Rep1 f), Generic1 f) => Eq1 (FunctorClassesDefault f) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

Methods

liftEq :: (a -> b -> Bool) -> FunctorClassesDefault f a -> FunctorClassesDefault f b -> Bool #

(GOrd1 (Rep1 f), Generic1 f) => Ord1 (FunctorClassesDefault f) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

(GRead1 (Rep1 f), Generic1 f) => Read1 (FunctorClassesDefault f) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

(GShow1 (Rep1 f), Generic1 f) => Show1 (FunctorClassesDefault f) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> FunctorClassesDefault f a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [FunctorClassesDefault f a] -> ShowS #

(GEq (Rep1 f a), Generic1 f) => Eq (FunctorClassesDefault f a) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

(GOrd (Rep1 f a), Generic1 f) => Ord (FunctorClassesDefault f a) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

(GRead (Rep1 f a), Generic1 f) => Read (FunctorClassesDefault f a) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

(GShow (Rep1 f a), Generic1 f) => Show (FunctorClassesDefault f a) Source # 
Instance details

Defined in Data.Functor.Classes.Generic.Internal

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 Eq1 Pair where
    liftEq = liftEqDefault

instance Ord1 Pair where
    liftCompare = liftCompareDefault

instance Read1 Pair where
    liftReadsPrec = liftReadsPrecDefault

instance Show1 Pair where
    liftShowsPrec = liftShowsPrecDefault