HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

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

Modulederiving-compat-0.6.8Haskell2010

Data.Deriving.Via.Internal

On template-haskell-2.12 or later (i.e., GHC 8.2 or later), this module exports functionality which emulates the GeneralizedNewtypeDeriving and DerivingVia GHC extensions (the latter of which was introduced in GHC 8.6).

On older versions of template-haskell/GHC, this module does not export anything.

Note: this is an internal module, and as such, the API presented here is not guaranteed to be stable, even between minor releases of this library.

  • 11 values
valuederiveGND :: Q Type -> Q [Dec]
#

Generates an instance for a type class at a newtype by emulating the behavior of the GeneralizedNewtypeDeriving extension. For example:

newtype Foo a = MkFoo a
$(deriveGND [t| forall a. Eq a => Eq (Foo a) |])
valuederiveVia :: Q Type -> Q [Dec]
#

Generates an instance for a type class by emulating the behavior of the DerivingVia extension. For example:

newtype Foo a = MkFoo a
$(deriveVia [t| forall a. Ord a => Ord (Foo a) `Via` Down a |])

As shown in the example above, the syntax is a tad strange. One must specify the type by which to derive the instance using the Via type. This requirement is in place to ensure that the type variables are scoped correctly across all the types being used (e.g., to make sure that the same a is used in Ord a, Ord (Foo a), and Down a).

valuechangeLast :: [a] -> a -> [a]
#

Replace the last element of a list with another element.