@@ -1,12 +1,16 @@
1−{-# LANGUAGE DeriveDataTypeable, DeriveGeneric,
2− GeneralizedNewtypeDeriving #-}
1+{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2+#ifdef GHC_GENERICS
3+{-# LANGUAGE DeriveGeneric, StandaloneDeriving #-}
4+#endif
35
46module Types where
57
68import qualified Data.Map as Map
79import Data.Data
810import Data.Text
11+#ifdef GHC_GENERICS
912import GHC.Generics
13+#endif
1014
1115data Foo = Foo {
1216 fooInt :: Int
@@ -15,35 +19,35 @@ data Foo = Foo {
1519 -- This definition causes an infinite loop in genericTo and genericFrom!
1620 -- , fooMap :: Map.Map String Foo
1721 , fooMap :: Map.Map String (Text,Int)
18− } deriving (Show, Typeable, Data, Generic)
22+ } deriving (Show, Typeable, Data)
1923
2024data UFoo = UFoo {
2125 _UFooInt :: Int
2226 , uFooInt :: Int
23− } deriving (Show, Eq, Data, Typeable, Generic)
27+ } deriving (Show, Eq, Data, Typeable)
2428
2529data OneConstructor = OneConstructor
26− deriving (Show, Eq, Typeable, Data, Generic)
30+ deriving (Show, Eq, Typeable, Data)
2731
2832data Product2 a b = Product2 a b
29− deriving (Show, Eq, Typeable, Data, Generic)
33+ deriving (Show, Eq, Typeable, Data)
3034
3135data Product6 a b c d e f = Product6 a b c d e f
32− deriving (Show, Eq, Typeable, Data, Generic)
36+ deriving (Show, Eq, Typeable, Data)
3337
3438data Sum4 a b c d = Alt1 a | Alt2 b | Alt3 c | Alt4 d
35− deriving (Show, Eq, Typeable, Data, Generic)
39+ deriving (Show, Eq, Typeable, Data)
3640
3741class ApproxEq a where
3842 (=~) :: a -> a -> Bool
3943
4044newtype Approx a = Approx { fromApprox :: a }
41− deriving (Show, Data, Typeable, Generic, ApproxEq, Num)
45+ deriving (Show, Data, Typeable, ApproxEq, Num)
4246
4347instance (ApproxEq a) => Eq (Approx a) where
4448 Approx a == Approx b = a =~ b
4549
46−data Nullary = C1 | C2 | C3 deriving (Eq, Show, Generic)
50+data Nullary = C1 | C2 | C3 deriving (Eq, Show)
4751
4852data SomeType a = Nullary
4953 | Unary Int
@@ -51,4 +55,16 @@ data SomeType a = Nullary
5155 | Record { testOne :: Double
5256 , testTwo :: Maybe Bool
5357 , testThree :: Maybe a
54− } deriving (Eq, Show, Generic)
58+ } deriving (Eq, Show)
59+
60+#ifdef GHC_GENERICS
61+deriving instance Generic Foo
62+deriving instance Generic UFoo
63+deriving instance Generic OneConstructor
64+deriving instance Generic (Product2 a b)
65+deriving instance Generic (Product6 a b c d e f)
66+deriving instance Generic (Sum4 a b c d)
67+deriving instance Generic (Approx a)
68+deriving instance Generic Nullary
69+deriving instance Generic (SomeType a)
70+#endif