aboutsummaryrefslogtreecommitdiff
path: root/standalone/no-th/haskell-patches/reflection_remove-TH.patch
blob: 7c63f05fcf737f03add2940bc3e24b7e62030b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
From 22c68b43dce437b3c22956f5a968f1b886e60e0c Mon Sep 17 00:00:00 2001
From: Joey Hess <joey@kitenet.net>
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