deriving-compat
Backports of GHC deriving extensions
https://github.com/haskell-compat/deriving-compat
| LTS Haskell 24.16: | 0.6.7@rev:1 |
| Stackage Nightly 2025-10-24: | 0.6.7@rev:1 |
| Latest on Hackage: | 0.6.7@rev:1 |
deriving-compat-0.6.7@sha256:b4edb909e6ecc7e0c88dda5f7f25579ed682ab3a97388e9a9e1976aa9ca0b772,7986Module documentation for 0.6.7
- Data
- Data.Bounded
- Data.Deriving
- Data.Enum
- Data.Eq
- Data.Foldable
- Data.Functor
- Data.Ix
- Data.Ord
- Data.Traversable
- Text
deriving-compat
deriving-compat provides Template Haskell functions that mimic deriving extensions that were introduced or modified in recent versions of GHC. Currently, the following typeclasses/extensions are covered:
- Deriving
Bounded - Deriving
Enum - Deriving
Ix - Deriving
Eq - Deriving
Ord - Deriving
Read - Deriving
Show DeriveFoldableDeriveFunctorDeriveTraversableGeneralizedNewtypeDeriving(with GHC 8.2 or later)DerivingVia(with GHC 8.2 or later)
See the Data.Deriving module for a full list of backported changes.
In addition, deriving-compat also provides some additional deriving functionality that has not yet been merged into upstream GHC. Aside from the GHC deriving extensions mentioned above, deriving-compat also permits deriving instances of classes in the Data.Functor.Classes module, covering the Eq1, Eq2, Ord1, Ord2, Read1, Read2, Show1, and Show2 classes. This extra functionality is outside of the main scope of deriving-compat, as it does not backport extensions that exist in today’s GHC. Nevertheless, the underlying Template Haskell machinery needed to derive Eq and friends extends very naturally to Eq1 and friends, so this extra functionality is included in deriving-compat as a convenience.
Note that some recent GHC typeclasses/extensions are not covered by this package:
DeriveDataTypeableDeriveGeneric, which was introducted in GHC 7.2 for derivingGenericinstances, and modified in GHC 7.6 to allow derivation ofGeneric1instances. UseGenerics.Deriving.THfromgeneric-derivingto deriveGeneric(1)using Template Haskell.DeriveLift, which was introduced in GHC 8.0 for derivingLiftinstances. UseLanguage.Haskell.TH.Liftfromth-liftto deriveLiftusing Template Haskell.- The
Bifunctortypeclass, which was introduced in GHC 7.10, as well as theBifoldableandBitraversabletypeclasses, which were introduced in GHC 8.2. UseData.Bifunctor.THfrombifunctorsto derive these typeclasses using Template Haskell.
Changes
0.6.7 [2024.12.05]
- Drop support for pre-8.0 versions of GHC.
0.6.6 [2024.03.19]
- Support building with
template-haskell-2.22.*(GHC 9.10).
0.6.5 [2023.08.06]
- When generating
Show(1)(2)instances withText.Show.Derivingusing GHC 9.8 or later, data types that have fields of typeInt{8,16,32,64}#orWord{8,16,32,64}#will be printed using extended literal syntax, mirroring corresponding changes introduced in GHC 9.8 (see https://github.com/ghc-proposals/ghc-proposals/pull/596).
0.6.4 [2023.08.06]
- Support building with
template-haskell-2.21.*(GHC 9.8). - The Template Haskell machinery now uses
TemplateHaskellQuoteswhen building with GHC 8.0+ instead of manually constructing each Template HaskellName. A consequence of this is thatderiving-compatwill now build with GHC 9.8, asTemplateHaskellQuotesabstracts over some internal Template Haskell changes introduced in 9.8.
0.6.3 [2023.02.27]
- Support
th-abstraction-0.5.*.
0.6.2 [2022.12.07]
- Make the test suite build with GHC 9.6 or later.
0.6.1 [2022.05.07]
- Backport GHC!6955,
which makes derived
Eqinstances check data constructor tags, which can improve runtime performance for data types with nullary constructors. - Allow building the test suite with
transformers-0.6.*.
0.6 [2021.08.29]
- Allow building with
template-haskell-2.18.0.0(GHC 9.2). - Using
deriveEnumandderiveIxon poly-kinded data family instances may now require the use of theTypeInTypeextension if using GHC 8.0, 8.2, or 8.4. (On later versions of GHC,TypeInType’s functionality has been folded intoPolyKinds.) - Support deriving
Eq,Ord, andShowinstances for data types with fields of typeInt32#orWord32#on GHC 9.2 or later. deriveVianow instantiates “floating”viatype variables (i.e., type variables mentioned in theviatype that are not mentioned in the instance context or the first argument toVia) toAnyin the generated code. As a result,deriveViano longer generates code that produces-Wunused-forallswarnings.
0.5.10 [2020.09.30]
- Allow building with
template-haskell-2.17.0.0(GHC 9.0).
0.5.9 [2019.06.08]
- Have
deriveFunctorandderiveFoldablederive implementations of(<$)andnull, which GHC starting doing in 8.2 and 8.4, respectively. - Fix a bug in which
deriveOrd{,1,2}could generate incorrect code for data types with a combination of nullary and non-nullary constructors. - Fix a bug in which
deriveFunctorwould fail on sufficiently complex uses of rank-n types in constructor fields. - Fix a bug in which
deriveFunctorand related functions would needlessly reject data types whose last type parameters appear as oversaturated arguments to a type family.
0.5.8 [2019.11.26]
- Allow building with GHC 8.10.
0.5.7 [2019.08.27]
-
Permit
deriveViato use “floating”viatype variables, such as theain:deriveVia [t| forall a. Show MyInt `Via` Const Int a |]
0.5.6 [2019.05.02]
- Support deriving
Eq,Ord, andShowinstances for data types with fields of typeInt8#,Int16#,Word8#, orWord16#on GHC 8.8 or later.
0.5.5 [2019.04.26]
- Support
th-abstraction-0.3or later.
0.5.4 [2019.01.21]
- Expose
Internalmodules.
0.5.3 [2019.01.20]
- Fix a bug in which
deriveEnum/deriveIxwould generate ill-scoped code for certain poly-kinded data types.
0.5.2 [2018.09.13]
- Fix a bug (on GHC 8.7 and above) in which
deriveGND/deriveViawould generate ill-scoped code.
0.5.1 [2018.07.11]
- Have
deriveGND/deriveViathrow an error if an incorrect number of arguments are supplied to the type class.
0.5 [2018.07.01]
-
Backport the changes to
GeneralizedNewtypeDerivingandDerivingViacode generation from Trac #15290.As a result, code generated by
deriveGNDorderiveVianow requires theInstanceSigsandScopedTypeVariableslanguage extensions. On the other hand, the generated code no longer requires theImpredicativeTypesextension (unless any class methods use higher-rank types). -
Allow building with
containers-0.6andtemplate-haskell-2.14.
0.4.3 [2018.06.16]
- Fix a bug that caused debug-enabled GHC builds to panic when generating code from this library (see Trac #15270). The fix only affects the library’s internals, so no changes are user-facing.
0.4.2 [2018.05.14]
- Backport the fixes for GHC Trac
#14364
and
#14918,
which significantly improve the compliation times of derived
Readinstances.
0.4.1 [2018.02.04]
- Add
Data.Deriving.Via, which allows emulating the behavior of theGeneralizedNewtypeDerivingandDerivingViaextensions. - Test suite fixes for GHC 8.4.
0.4 [2017.12.07]
- Incorporate changes from the
EmptyDataDerivingproposal (which is in GHC as of 8.4):- For derived
EqandOrdinstances for empty data types, simply returnTrueandEQ, respectively, without inspecting the arguments. - For derived
Readinstances for empty data types, simply returnpfail(withoutparens). - For derived
Showinstances for empty data types, inspect the argument (instead oferroring). In addition, addshowEmptyCaseBehaviortoShowOptions, which configures whether derived instances for empty data types should use theEmptyCaseextension (this is disabled by default). - For derived
FunctorandTraversableinstances for empty data types, makefmapandtraversestrict in its argument. - For derived
Foldableinstances, do not error on empty data types. Instead, simply return the folded state (forfoldr) ormempty(forfoldMap), without inspecting the arguments. - Add
FFTOptions(Functor/Foldable/Traversableoptions) toData.Functor.Deriving, along with variants of existing functions that takeFFTOptionsas an argument. For now, the only configurable option is whether derived instances for empty data types should use theEmptyCaseextension (this is disabled by default).
- For derived
- Backport the fix to #13328. That is, when deriving
FunctororTraversableinstances for data types where the last type variable is at phantom role, generatedfmap/traverseimplementations now usecoercefor efficiency. - Rename
emptyCaseBehaviorfromData.Functor.DerivingtofftEmptyCaseBehavior.
0.3.6 [2017.04.10]
- Make
deriveTraversableuseliftA2in derived implementations oftraversewhen possible, now thatliftA2is a class method ofApplicative(as of GHC 8.2) - Make
deriveShowuseshowCommaSpace, a change introduced in GHC 8.2
0.3.5 [2016.12.12]
- Fix bug in which derived
Ordinstances for datatypes with many constructors would fail to typecheck
0.3.4 [2016.10.20]
- Fix bug in which infix record selectors weren’t shown with parentheses in derived
Showinstances - Fix bug in which record selectors weren’t parsed correctly in derived
Readinstances
0.3.3 [2016.09.11]
- Add
Data.Bounded.Deriving, which allows derivingBoundedwith TH. - Add
Data.Enum.Deriving, which allows derivingEnumwith TH. - Add
Data.Ix.Deriving, which allows derivingIxwith TH. - Fix bug in which derived
Showinstance would parenthesize the output too eagerly
0.3.2
- Incorporate a fix to GHC Trac #10858, which will be introduced in GHC 8.2
- Fix bug in which derived
Ordinstances accidentally swapped their less-than(-or-equal-to) and greater-than(-or-equal-to) methods - Fix GHC HEAD build
0.3.1
- Allow deriving
FunctorandFoldableinstances for datatypes containing unboxed tuples - Microoptimization in derived instances of higher-order versions of
Eq,Ord,Read, andShow
0.3
- Added
Data.Eq.Deriving, which allows derivingEq,Eq1, andEq2with TH. - Added
Data.Ord.Deriving, which allows derivingOrd,Ord1, andOrd2with TH. - Added
Data.Read.Deriving, which allows derivingRead,Read1, andEq2with TH. - Renamed
Text.Show.Deriving.OptionstoShowOptionsso as to disambiguate it from the options datatypes in otherderiving-compatmodules.
0.2.2
- Fixed a bug in
Text.Show.Deriving’s treatment of unlifted types
0.2.1
- Added
Text.Show.Deriving, which allows derivingShow,Show1, andShow2with TH.
0.2
- Added support for GHC 8.0
- Added
Data.Functor.DerivingandData.Traversable.Deriving, which allow derivingFunctorandTraversablewith TH. - Added
Data.Deriving, which reexports all other modules
0.1
- Initial commit