File: Generic.hs

package info (click to toggle)
haskell-transformers-compat 0.7.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 332 kB
  • sloc: haskell: 4,049; makefile: 3
file content (115 lines) | stat: -rw-r--r-- 2,914 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{-# LANGUAGE CPP #-}

{-|
Module:      Data.Functor.Classes.Generic
Copyright:   (C) 2015-2016 Edward Kmett, Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

Functions to generically derive 'C.Eq1', 'C.Ord1', 'C.Read1', and 'C.Show1'
instances from "Data.Functor.Classes".
-}
module Data.Functor.Classes.Generic
  ( -- * Options
    Options(..)
  , defaultOptions
  , latestGHCOptions
#if defined(TRANSFORMERS_FOUR)
    -- * 'Eq1'
  , eq1Default
  , eq1Options
    -- * 'Ord1'
  , compare1Default
  , compare1Options
    -- * 'Read1'
  , readsPrec1Default
  , readsPrec1Options
    -- * 'Show1'
  , showsPrec1Default
  , showsPrec1Options
#else
    -- * 'Eq1'
  , liftEqDefault
  , liftEqOptions
    -- * 'Ord1'
  , liftCompareDefault
  , liftCompareOptions
    -- * 'Read1'
  , liftReadsPrecDefault
  , liftReadsPrecOptions
    -- * 'Show1'
  , liftShowsPrecDefault
  , liftShowsPrecOptions
#endif
    -- * 'GenericFunctorClasses'
  , FunctorClassesDefault(..)
    -- * Example
    -- $example
  ) where

import qualified Data.Functor.Classes as C ()
import           Data.Functor.Classes.Generic.Internal

#undef MIN_VERSION_transformers
{- $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.
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
@
-}