summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2015-05-04 15:24:34 -0700
committerEdward Z. Yang <ezyang@cs.stanford.edu>2015-05-28 17:37:03 -0700
commitb0d8ba368f031279444c851dbca499d7e272f74c (patch)
tree117cb8e6e0b6724df628528e9e48d75d7c1363c3 /libraries
parente28462de700240288519a016d0fe44d4360d9ffd (diff)
downloadhaskell-b0d8ba368f031279444c851dbca499d7e272f74c.tar.gz
Add liftData function.
Summary: See https://mail.haskell.org/pipermail/libraries/2015-April/025480.html for the proposal and discussion Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: austin Subscribers: bgamari, thomie Differential Revision: https://phabricator.haskell.org/D879
Diffstat (limited to 'libraries')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Quote.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Quote.hs b/libraries/template-haskell/Language/Haskell/TH/Quote.hs
index 39cd2bace8..66ee115b61 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Quote.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Quote.hs
@@ -16,6 +16,7 @@ that is up to you.
module Language.Haskell.TH.Quote(
QuasiQuoter(..),
dataToQa, dataToExpQ, dataToPatQ,
+ liftData,
quoteFile
) 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.