summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2014-12-19 10:29:54 -0500
committerRichard Eisenberg <eir@cis.upenn.edu>2014-12-19 11:06:34 -0500
commit2e28c8262f8e329c3b5cf0c6782a4a810e490e82 (patch)
tree70fa63b5253ad7c8e48fa9f536fa015ca5aff203
parentdd1b6d4fc96bc2779beaca836d1b9e4b158c1597 (diff)
downloadhaskell-2e28c8262f8e329c3b5cf0c6782a4a810e490e82.tar.gz
Add instance Lift Natural
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs5
-rw-r--r--testsuite/tests/th/TH_Lift.hs4
2 files changed, 9 insertions, 0 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 8e4b34462d..29be27a9a2 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 fd30af738b..eff0f1b18f 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) )