[commit: ghc] master: Add liftData function. (b0d8ba3)

git at git.haskell.org git at git.haskell.org
Fri May 29 00:37:18 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/b0d8ba368f031279444c851dbca499d7e272f74c/ghc

>---------------------------------------------------------------

commit b0d8ba368f031279444c851dbca499d7e272f74c
Author: Edward Z. Yang <ezyang at cs.stanford.edu>
Date:   Mon May 4 15:24:34 2015 -0700

    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 at cs.stanford.edu>
    
    Test Plan: validate
    
    Reviewers: austin
    
    Subscribers: bgamari, thomie
    
    Differential Revision: https://phabricator.haskell.org/D879


>---------------------------------------------------------------

b0d8ba368f031279444c851dbca499d7e272f74c
 libraries/template-haskell/Language/Haskell/TH/Quote.hs | 10 ++++++++--
 1 file 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 39cd2ba..66ee115 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.



More information about the ghc-commits mailing list