Language.Haskell.TH.Lift

th-lift-0.8.2: Derive Template Haskell's Lift class for datatypes.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Language.Haskell.TH.Lift

Contents

- Orphan instances

Synopsis

- deriveLift :: Name -> Q [Dec]
- deriveLiftMany :: [Name] -> Q [Dec]
- deriveLift' :: [Role] -> Info -> Q [Dec]
- deriveLiftMany' :: [([Role], Info)] -> Q [Dec]
- makeLift :: Name -> Q Exp
- makeLift' :: Info -> Q Exp
- class Lift (t :: TYPE r) where
  - lift :: Quote m => t -> m Exp
  - liftTyped :: forall (m :: Type -> Type). Quote m => t -> Code m t

# Documentation

deriveLift :: Name -> Q [Dec] #

deriveLiftMany :: [Name] -> Q [Dec] #

Derive `Lift` instances for many datatypes.

deriveLift' :: [Role] -> Info -> Q [Dec] #

Obtain `Info` values through a custom reification function. This is useful when generating instances for datatypes that have not yet been declared.

deriveLiftMany' :: [([Role], Info)] -> Q [Dec] #

makeLift :: Name -> Q Exp #

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.

makeLift' :: Info -> Q Exp #

Like `makeLift`, but using a custom reification function.

class Lift (t :: TYPE r) where #

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

Levity-polymorphic since template-haskell-2.16.0.0.

Minimal complete definition

liftTyped

Methods

lift :: Quote m => t -> m Exp #

Turn a value into a Template Haskell expression, suitable for use in a splice.

liftTyped :: forall (m :: Type -> Type). Quote m => t -> Code m t #

Turn a value into a Template Haskell typed expression, suitable for use in a typed splice.

Since: template-haskell-2.16.0.0

#### Instances

Instances details

Lift Addr# | Produces an `Addr#` literal from the NUL-terminated C-string starting at the given memory address. Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Addr# -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Addr# -> Code m Addr# #
Lift Double# | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Double# -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Double# -> Code m Double# #
Lift Float# | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Float# -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Float# -> Code m Float# #
Lift Int# | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Int# -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Int# -> Code m Int# #
Lift Void | Since: template-haskell-2.15.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Void -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Void -> Code m Void #
Lift Int16 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Int16 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Int16 -> Code m Int16 #
Lift Int32 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Int32 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Int32 -> Code m Int32 #
Lift Int64 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Int64 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Int64 -> Code m Int64 #
Lift Int8 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Int8 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Int8 -> Code m Int8 #
Lift Word16 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Word16 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Word16 -> Code m Word16 #
Lift Word32 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Word32 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Word32 -> Code m Word32 #
Lift Word64 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Word64 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Word64 -> Code m Word64 #
Lift Word8 |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Word8 -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Word8 -> Code m Word8 #
Lift ModName # |
Instance details Defined in Language.Haskell.TH.Lift Methods lift :: Quote m => ModName -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ModName -> Code m ModName #
Lift Name # |
Instance details Defined in Language.Haskell.TH.Lift Methods lift :: Quote m => Name -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Name -> Code m Name #
Lift NameFlavour # |
Instance details Defined in Language.Haskell.TH.Lift Methods lift :: Quote m => NameFlavour -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => NameFlavour -> Code m NameFlavour #
Lift NameSpace # |
Instance details Defined in Language.Haskell.TH.Lift Methods lift :: Quote m => NameSpace -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => NameSpace -> Code m NameSpace #
Lift OccName # |
Instance details Defined in Language.Haskell.TH.Lift Methods lift :: Quote m => OccName -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => OccName -> Code m OccName #
Lift PkgName # |
Instance details Defined in Language.Haskell.TH.Lift Methods lift :: Quote m => PkgName -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => PkgName -> Code m PkgName #
Lift Integer |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Integer -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Integer -> Code m Integer #
Lift Natural |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Natural -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Natural -> Code m Natural #
Lift () |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => () -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => () -> Code m () #
Lift Bool |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Bool -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Bool -> Code m Bool #
Lift Char |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Char -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Char -> Code m Char #
Lift Double |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Double -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Double -> Code m Double #
Lift Float |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Float -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Float -> Code m Float #
Lift Int |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Int -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Int -> Code m Int #
Lift Word |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Word -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Word -> Code m Word #
Lift Char# | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Char# -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Char# -> Code m Char# #
Lift Word# | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Word# -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Word# -> Code m Word# #
Integral a => Lift (Ratio a :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Ratio a -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Ratio a -> Code m (Ratio a) #
Lift a => Lift (NonEmpty a :: Type) | Since: template-haskell-2.15.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => NonEmpty a -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => NonEmpty a -> Code m (NonEmpty a) #
Lift a => Lift (Maybe a :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Maybe a -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Maybe a -> Code m (Maybe a) #
Lift a => Lift ([a] :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => [a] -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => [a] -> Code m [a] #
(Lift a, Lift b) => Lift (Either a b :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => Either a b -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Either a b -> Code m (Either a b) #
(Lift a, Lift b) => Lift ((a, b) :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (a, b) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (a, b) -> Code m (a, b) #
(Lift a, Lift b, Lift c) => Lift ((a, b, c) :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (a, b, c) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (a, b, c) -> Code m (a, b, c) #
(Lift a, Lift b, Lift c, Lift d) => Lift ((a, b, c, d) :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (a, b, c, d) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (a, b, c, d) -> Code m (a, b, c, d) #
(Lift a, Lift b, Lift c, Lift d, Lift e) => Lift ((a, b, c, d, e) :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (a, b, c, d, e) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (a, b, c, d, e) -> Code m (a, b, c, d, e) #
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f) => Lift ((a, b, c, d, e, f) :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (a, b, c, d, e, f) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (a, b, c, d, e, f) -> Code m (a, b, c, d, e, f) #
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g) => Lift ((a, b, c, d, e, f, g) :: Type) |
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (a, b, c, d, e, f, g) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (a, b, c, d, e, f, g) -> Code m (a, b, c, d, e, f, g) #
Lift (# #) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# #) -> Code m (# #) #
Lift a => Lift ((# a #) :: TYPE ('TupleRep '['BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a #) -> Code m (# a #) #
(Lift a, Lift b) => Lift ((# a | b #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a | b #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a | b #) -> Code m (# a | b #) #
(Lift a, Lift b) => Lift ((# a, b #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a, b #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a, b #) -> Code m (# a, b #) #
(Lift a, Lift b, Lift c) => Lift ((# a | b | c #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a | b | c #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a | b | c #) -> Code m (# a | b | c #) #
(Lift a, Lift b, Lift c) => Lift ((# a, b, c #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a, b, c #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a, b, c #) -> Code m (# a, b, c #) #
(Lift a, Lift b, Lift c, Lift d) => Lift ((# a | b | c | d #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a | b | c | d #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a | b | c | d #) -> Code m (# a | b | c | d #) #
(Lift a, Lift b, Lift c, Lift d) => Lift ((# a, b, c, d #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a, b, c, d #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a, b, c, d #) -> Code m (# a, b, c, d #) #
(Lift a, Lift b, Lift c, Lift d, Lift e) => Lift ((# a | b | c | d | e #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a | b | c | d | e #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a | b | c | d | e #) -> Code m (# a | b | c | d | e #) #
(Lift a, Lift b, Lift c, Lift d, Lift e) => Lift ((# a, b, c, d, e #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a, b, c, d, e #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a, b, c, d, e #) -> Code m (# a, b, c, d, e #) #
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f) => Lift ((# a | b | c | d | e | f #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a | b | c | d | e | f #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a | b | c | d | e | f #) -> Code m (# a | b | c | d | e | f #) #
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f) => Lift ((# a, b, c, d, e, f #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a, b, c, d, e, f #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a, b, c, d, e, f #) -> Code m (# a, b, c, d, e, f #) #
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g) => Lift ((# a | b | c | d | e | f | g #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a | b | c | d | e | f | g #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a | b | c | d | e | f | g #) -> Code m (# a | b | c | d | e | f | g #) #
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g) => Lift ((# a, b, c, d, e, f, g #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0
Instance details Defined in Language.Haskell.TH.Syntax Methods lift :: Quote m => (# a, b, c, d, e, f, g #) -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => (# a, b, c, d, e, f, g #) -> Code m (# a, b, c, d, e, f, g #) #

# Orphan instances

Lift ModName # |
Instance details Methods lift :: Quote m => ModName -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ModName -> Code m ModName #
Lift Name # |
Instance details Methods lift :: Quote m => Name -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Name -> Code m Name #
Lift NameFlavour # |
Instance details Methods lift :: Quote m => NameFlavour -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => NameFlavour -> Code m NameFlavour #
Lift NameSpace # |
Instance details Methods lift :: Quote m => NameSpace -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => NameSpace -> Code m NameSpace #
Lift OccName # |
Instance details Methods lift :: Quote m => OccName -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => OccName -> Code m OccName #
Lift PkgName # |
Instance details Methods lift :: Quote m => PkgName -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => PkgName -> Code m PkgName #