[commit: ghc] master: Add instance Lift Natural (2e28c82)

git at git.haskell.org git at git.haskell.org
Fri Dec 19 16:05:33 UTC 2014


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

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

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

commit 2e28c8262f8e329c3b5cf0c6782a4a810e490e82
Author: Richard Eisenberg <eir at cis.upenn.edu>
Date:   Fri Dec 19 10:29:54 2014 -0500

    Add instance Lift Natural


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

2e28c8262f8e329c3b5cf0c6782a4a810e490e82
 libraries/template-haskell/Language/Haskell/TH/Syntax.hs | 5 +++++
 testsuite/tests/th/TH_Lift.hs                            | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 8e4b344..29be27a 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -29,6 +29,7 @@ import Data.Char        ( isAlpha, isAlphaNum, isUpper )
 import Data.Int
 import Data.Word
 import Data.Ratio
+import Numeric.Natural
 import GHC.Generics     ( Generic )
 
 -----------------------------------------------------
@@ -452,6 +453,7 @@ sequenceQ = sequence
 class Lift t where
   lift :: t -> Q Exp
 
+-- If you add any instances here, consider updating test th/TH_Lift
 instance Lift Integer where
   lift x = return (LitE (IntegerL x))
 
@@ -485,6 +487,9 @@ instance Lift Word32 where
 instance Lift Word64 where
   lift x = return (LitE (IntegerL (fromIntegral x)))
 
+instance Lift Natural where
+  lift x = return (LitE (IntegerL (fromIntegral x)))
+
 instance Integral a => Lift (Ratio a) where
   lift x = return (LitE (RationalL (toRational x)))
 
diff --git a/testsuite/tests/th/TH_Lift.hs b/testsuite/tests/th/TH_Lift.hs
index fd30af7..eff0f1b 100644
--- a/testsuite/tests/th/TH_Lift.hs
+++ b/testsuite/tests/th/TH_Lift.hs
@@ -8,6 +8,7 @@ import Language.Haskell.TH.Syntax
 import Data.Ratio
 import Data.Word
 import Data.Int
+import Numeric.Natural
 
 a :: Integer
 a = $( (\x -> [| x |]) (5 :: Integer) )
@@ -42,6 +43,9 @@ f = $( (\x -> [| x |]) (5 :: Word32) )
 g :: Word64
 g = $( (\x -> [| x |]) (5 :: Word64) )
 
+g1 :: Natural
+g1 = $( (\x -> [| x |]) (5 :: Natural) )
+
 h :: Rational
 h = $( (\x -> [| x |]) (5 % 3 :: Rational) )
 



More information about the ghc-commits mailing list