Commit 2e28c826 authored by eir@cis.upenn.edu's avatar eir@cis.upenn.edu
Browse files

Add instance Lift Natural

parent dd1b6d4f
...@@ -29,6 +29,7 @@ import Data.Char ( isAlpha, isAlphaNum, isUpper ) ...@@ -29,6 +29,7 @@ import Data.Char ( isAlpha, isAlphaNum, isUpper )
import Data.Int import Data.Int
import Data.Word import Data.Word
import Data.Ratio import Data.Ratio
import Numeric.Natural
import GHC.Generics ( Generic ) import GHC.Generics ( Generic )
----------------------------------------------------- -----------------------------------------------------
...@@ -452,6 +453,7 @@ sequenceQ = sequence ...@@ -452,6 +453,7 @@ sequenceQ = sequence
class Lift t where class Lift t where
lift :: t -> Q Exp lift :: t -> Q Exp
-- If you add any instances here, consider updating test th/TH_Lift
instance Lift Integer where instance Lift Integer where
lift x = return (LitE (IntegerL x)) lift x = return (LitE (IntegerL x))
...@@ -485,6 +487,9 @@ instance Lift Word32 where ...@@ -485,6 +487,9 @@ instance Lift Word32 where
instance Lift Word64 where instance Lift Word64 where
lift x = return (LitE (IntegerL (fromIntegral x))) 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 instance Integral a => Lift (Ratio a) where
lift x = return (LitE (RationalL (toRational x))) lift x = return (LitE (RationalL (toRational x)))
......
...@@ -8,6 +8,7 @@ import Language.Haskell.TH.Syntax ...@@ -8,6 +8,7 @@ import Language.Haskell.TH.Syntax
import Data.Ratio import Data.Ratio
import Data.Word import Data.Word
import Data.Int import Data.Int
import Numeric.Natural
a :: Integer a :: Integer
a = $( (\x -> [| x |]) (5 :: Integer) ) a = $( (\x -> [| x |]) (5 :: Integer) )
...@@ -42,6 +43,9 @@ f = $( (\x -> [| x |]) (5 :: Word32) ) ...@@ -42,6 +43,9 @@ f = $( (\x -> [| x |]) (5 :: Word32) )
g :: Word64 g :: Word64
g = $( (\x -> [| x |]) (5 :: Word64) ) g = $( (\x -> [| x |]) (5 :: Word64) )
g1 :: Natural
g1 = $( (\x -> [| x |]) (5 :: Natural) )
h :: Rational h :: Rational
h = $( (\x -> [| x |]) (5 % 3 :: Rational) ) h = $( (\x -> [| x |]) (5 % 3 :: Rational) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment