From 22c68b43dce437b3c22956f5a968f1b886e60e0c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 17 Dec 2013 19:15:16 +0000 Subject: [PATCH] remove TH --- fast/Data/Reflection.hs | 80 +------------------------------------------------ 1 file changed, 1 insertion(+), 79 deletions(-) diff --git a/fast/Data/Reflection.hs b/fast/Data/Reflection.hs index 119d773..cf99efa 100644 --- a/fast/Data/Reflection.hs +++ b/fast/Data/Reflection.hs @@ -58,7 +58,7 @@ module Data.Reflection , Given(..) , give -- * Template Haskell reflection - , int, nat + --, int, nat -- * Useful compile time naturals , Z, D, SD, PD ) where @@ -151,87 +151,9 @@ instance Reifies n Int => Reifies (PD n) Int where reflect = (\n -> n + n - 1) <$> retagPD reflect {-# INLINE reflect #-} --- | This can be used to generate a template haskell splice for a type level version of a given 'int'. --- --- This does not use GHC TypeLits, instead it generates a numeric type by hand similar to the ones used --- in the \"Functional Pearl: Implicit Configurations\" paper by Oleg Kiselyov and Chung-Chieh Shan. -int :: Int -> TypeQ -int n = case quotRem n 2 of - (0, 0) -> conT ''Z - (q,-1) -> conT ''PD `appT` int q - (q, 0) -> conT ''D `appT` int q - (q, 1) -> conT ''SD `appT` int q - _ -> error "ghc is bad at math" - --- | This is a restricted version of 'int' that can only generate natural numbers. Attempting to generate --- a negative number results in a compile time error. Also the resulting sequence will consist entirely of --- Z, D, and SD constructors representing the number in zeroless binary. -nat :: Int -> TypeQ -nat n - | n >= 0 = int n - | otherwise = error "nat: negative" - -#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL < 704 -instance Show (Q a) -instance Eq (Q a) -#endif -instance Num a => Num (Q a) where - (+) = liftM2 (+) - (*) = liftM2 (*) - (-) = liftM2 (-) - negate = fmap negate - abs = fmap abs - signum = fmap signum - fromInteger = return . fromInteger - -instance Fractional a => Fractional (Q a) where - (/) = liftM2 (/) - recip = fmap recip - fromRational = return . fromRational - --- | This permits the use of $(5) as a type splice. -instance Num Type where -#ifdef USE_TYPE_LITS - a + b = AppT (AppT (VarT ''(+)) a) b - a * b = AppT (AppT (VarT ''(*)) a) b -#if MIN_VERSION_base(4,8,0) - a - b = AppT (AppT (VarT ''(-)) a) b -#else - (-) = error "Type.(-): undefined" -#endif - fromInteger = LitT . NumTyLit -#else - (+) = error "Type.(+): undefined" - (*) = error "Type.(*): undefined" - (-) = error "Type.(-): undefined" - fromInteger n = case quotRem n 2 of - (0, 0) -> ConT ''Z - (q,-1) -> ConT ''PD `AppT` fromInteger q - (q, 0) -> ConT ''D `AppT` fromInteger q - (q, 1) -> ConT ''SD `AppT` fromInteger q - _ -> error "ghc is bad at math" -#endif - abs = error "Type.abs" - signum = error "Type.signum" - plus, times, minus :: Num a => a -> a -> a plus = (+) times = (*) minus = (-) fract :: Fractional a => a -> a -> a fract = (/) - --- | This permits the use of $(5) as an expression splice. -instance Num Exp where - a + b = AppE (AppE (VarE 'plus) a) b - a * b = AppE (AppE (VarE 'times) a) b - a - b = AppE (AppE (VarE 'minus) a) b - negate = AppE (VarE 'negate) - signum = AppE (VarE 'signum) - abs = AppE (VarE 'abs) - fromInteger = LitE . IntegerL - -instance Fractional Exp where - a / b = AppE (AppE (VarE 'fract) a) b - recip = AppE (VarE 'recip) - fromRational = LitE . RationalL -- 1.8.5.1