Commit b0d8ba36 authored by Edward Z. Yang's avatar Edward Z. Yang

Add liftData function.

for the proposal and discussion
Signed-off-by: default avatarEdward Z. Yang <>

Test Plan: validate

Reviewers: austin

Subscribers: bgamari, thomie

Differential Revision:
parent e28462de
......@@ -16,6 +16,7 @@ that is up to you.
module Language.Haskell.TH.Quote(
dataToQa, dataToExpQ, dataToPatQ,
) where
......@@ -88,14 +89,19 @@ dataToQa mkCon mkLit appCon antiQ t =
-- | 'dataToExpQ' converts a value to a 'Q Exp' representation of the
-- same value, in the SYB style. It is generalized to take a function
-- override type-specific cases; a useful default is 'const Nothing'
-- for no overriding.
-- override type-specific cases; see 'liftData' for a more commonly
-- used variant.
dataToExpQ :: Data a
=> (forall b . Data b => b -> Maybe (Q Exp))
-> a
-> Q Exp
dataToExpQ = dataToQa conE litE (foldl appE)
-- | 'liftData' is a variant of 'lift' in the 'Lift' type class which
-- works for any type with a 'Data' instance.
liftData :: Data a => a -> Q Exp
liftData = dataToExpQ (const Nothing)
-- | 'dataToPatQ' converts a value to a 'Q Pat' representation of the same
-- value, in the SYB style. It takes a function to handle type-specific cases,
-- alternatively, pass @const Nothing@ to get default behavior.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment