deriving-compat-0.6.6: Backports of GHC deriving extensions

Copyright | (C) 2015-2017 Ryan Scott
License | BSD-style (see the file LICENSE)
Maintainer | Ryan Scott
Portability | Template Haskell
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Traversable.Deriving

Contents

- `Traversable`
- `FFTOptions`
- `deriveTraversable` limitations

Description

Exports functions to mechanically derive `Traversable` instances in a way that mimics how the `-XDeriveTraversable` extension works since GHC 8.0.

Derived `Traversable` instances from this module do not generate superfluous `pure` expressions in its implementation of `traverse`. One can verify this by compiling a module that uses `deriveTraversable` with the `-ddump-splices` GHC flag.

These changes make it possible to derive `Traversable` instances for data types with unlifted argument types, e.g.,

    data IntHash a = IntHash Int# a

    deriving instance Traversable IntHash -- On GHC 8.0  on later
    $(deriveTraversable ''IntHash)        -- On GHC 7.10 and earlier

For more info on these changes, see this GHC wiki page.

Synopsis

- deriveTraversable :: Name -> Q [Dec]
- deriveTraversableOptions :: FFTOptions -> Name -> Q [Dec]
- makeTraverse :: Name -> Q Exp
- makeTraverseOptions :: FFTOptions -> Name -> Q Exp
- makeSequenceA :: Name -> Q Exp
- makeSequenceAOptions :: FFTOptions -> Name -> Q Exp
- makeMapM :: Name -> Q Exp
- makeMapMOptions :: FFTOptions -> Name -> Q Exp
- makeSequence :: Name -> Q Exp
- makeSequenceOptions :: FFTOptions -> Name -> Q Exp
- newtype FFTOptions = FFTOptions {
  - fftEmptyCaseBehavior :: Bool
  }
- defaultFFTOptions :: FFTOptions

# `Traversable`

deriveTraversable :: Name -> Q [Dec] Source #

Generates a `FunctorClass` instance declaration for the given data type or data family instance.

deriveTraversableOptions :: FFTOptions -> Name -> Q [Dec] Source #

Like `deriveTraverse`, but takes an `FFTOptions` argument.

makeTraverse :: Name -> Q Exp Source #

Generates a lambda expression which behaves like `traverse` (without requiring a `FunctorClass` instance).

makeTraverseOptions :: FFTOptions -> Name -> Q Exp Source #

Like `makeTraverse`, but takes an `FFTOptions` argument.

makeSequenceA :: Name -> Q Exp Source #

Generates a lambda expression which behaves like `sequenceA` (without requiring a `FunctorClass` instance).

makeSequenceAOptions :: FFTOptions -> Name -> Q Exp Source #

Like `makeSequenceA`, but takes an `FFTOptions` argument.

makeMapM :: Name -> Q Exp Source #

Generates a lambda expression which behaves like `mapM` (without requiring a `FunctorClass` instance).

makeMapMOptions :: FFTOptions -> Name -> Q Exp Source #

Like `makeMapM`, but takes an `FFTOptions` argument.

makeSequence :: Name -> Q Exp Source #

Generates a lambda expression which behaves like `sequence` (without requiring a `FunctorClass` instance).

makeSequenceOptions :: FFTOptions -> Name -> Q Exp Source #

Like `makeSequence`, but takes an `FFTOptions` argument.

# `FFTOptions`

newtype FFTOptions Source #

Options that further configure how the functions in Data.Functor.Deriving should behave. (`FFT` stands for `FunctorClass` `FunctorClass` `FunctorClass`.)

Constructors

FFTOptions |

Fields

- fftEmptyCaseBehavior :: Bool

  If `True`, derived instances for empty data types (i.e., ones with no data constructors) will use the `EmptyCase` language extension. If `False`, derived instances will simply use `seq` instead. (This has no effect on GHCs before 7.8, since `EmptyCase` is only available in 7.8 or later.)

#### Instances

Instances details

Read FFTOptions Source # |
Instance details Defined in Data.Functor.Deriving.Internal Methods readsPrec :: Int -> ReadS FFTOptions Source # readList :: ReadS [FFTOptions] Source # readPrec :: ReadPrec FFTOptions Source # readListPrec :: ReadPrec [FFTOptions] Source #
Show FFTOptions Source # |
Instance details Defined in Data.Functor.Deriving.Internal Methods showsPrec :: Int -> FFTOptions -> ShowS Source # show :: FFTOptions -> String Source # showList :: [FFTOptions] -> ShowS Source #
Eq FFTOptions Source # |
Instance details Defined in Data.Functor.Deriving.Internal Methods (==) :: FFTOptions -> FFTOptions -> Bool Source # (/=) :: FFTOptions -> FFTOptions -> Bool Source #
Ord FFTOptions Source # |

Instance details

Defined in Data.Functor.Deriving.Internal

Methods

compare :: FFTOptions -> FFTOptions -> Ordering Source #

(<) :: FFTOptions -> FFTOptions -> Bool Source #

(<=) :: FFTOptions -> FFTOptions -> Bool Source #

(>) :: FFTOptions -> FFTOptions -> Bool Source #

(>=) :: FFTOptions -> FFTOptions -> Bool Source #

max :: FFTOptions -> FFTOptions -> FFTOptions Source #

min :: FFTOptions -> FFTOptions -> FFTOptions Source #

defaultFFTOptions :: FFTOptions Source #

Conservative `FFTOptions` that doesn't attempt to use `EmptyCase` (to prevent users from having to enable that extension at use sites.)

# `deriveTraversable` limitations

Be aware of the following potential gotchas:

- If you are using the `-XGADTs` or `-XExistentialQuantification` extensions, an existential constraint cannot mention the last type variable. For example, `data Illegal a = forall a. Show a => Illegal a` cannot have a derived `Traversable` instance.
- Type variables of kind `* -> *` are assumed to have `Traversable` constraints. If this is not desirable, use `makeTraverse`.