From b0d8ba368f031279444c851dbca499d7e272f74c Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 4 May 2015 15:24:34 -0700 Subject: 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 Test Plan: validate Reviewers: austin Subscribers: bgamari, thomie Differential Revision: https://phabricator.haskell.org/D879 --- libraries/template-haskell/Language/Haskell/TH/Quote.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libraries') 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. -- cgit v1.2.1