lift package:th-lift

Turn a value into a Template Haskell expression, suitable for use in a splice.
A Lift instance can have any of its values turned into a Template Haskell expression. This is needed when a value used within a Template Haskell quotation is bound outside the Oxford brackets ([| ... |] or [|| ... ||]) but not at the top level. As an example:
add1 :: Int -> Q (TExp Int)
add1 x = [|| x + 1 ||]
Template Haskell has no way of knowing what value x will take on at splice-time, so it requires the type of x to be an instance of Lift. A Lift instance must satisfy $(lift x) ≡ x and $$(liftTyped x) ≡ x for all x, where $(...) and $$(...) are Template Haskell splices. It is additionally expected that lift x ≡ unTypeQ (liftTyped x). Lift instances can be derived automatically by use of the -XDeriveLift GHC language extension:
{-# LANGUAGE DeriveLift #-}
module Foo where

import Language.Haskell.TH.Syntax

data Bar a = Bar1 a (Bar a) | Bar2 String
deriving Lift
Representation-polymorphic since template-haskell-2.16.0.0.
Turn a value into a Template Haskell typed expression, suitable for use in a typed splice.
Derive Template Haskell's Lift class for datatypes. Derive Template Haskell's Lift class for datatypes using TemplateHaskell. The functionality in this package has largely been subsumed by the DeriveLift language extension, which is available in GHC 8.0 and later versions. As such, this package is only useful as a way to backport bugfixes to DeriveLift in later GHC versions back to older GHCs. The following libraries are related:
  • The th-orphans package provides instances for template-haskell syntax types.
  • The th-lift-instances package provides Lift instances for types in base, text, bytestring, vector, etc. Some of these instances are only provided for old versions of their respective libraries, as the same Lift instances are also present upstream on newer versions.
Obtain Info values through a custom reification function. This is useful when generating instances for datatypes that have not yet been declared.
Derive Lift instances for many datatypes.
Generates a lambda expresson which behaves like lift (without requiring a Lift instance). Example:
newtype Fix f = In { out :: f (Fix f) }

instance Lift (f (Fix f)) => Lift (Fix f) where
lift = $(makeLift ''Fix)
This can be useful when deriveLift is not clever enough to infer the correct instance context, such as in the example above.
Like makeLift, but using a custom reification function.