on master help sign in
Use generic-deriving to test data family generics on GHC 7.4
fdfbf2aAdam Bergmark
aeson.cabal+2−1
@@ -155,9 +155,10 @@ test-suite tests
155 aeson,
155 aeson,
156 attoparsec,
156 attoparsec,
157 base,
157 base,
158− base-orphans >=0.5.3 && <0.6,
158+ base-orphans >= 0.5.3 && <0.6,
159 bytestring,
159 bytestring,
160 containers,
160 containers,
161+ generic-deriving >= 1.10 && < 1.11,
161 ghc-prim >= 0.2,
162 ghc-prim >= 0.2,
162 hashable >= 1.1.2.0,
163 hashable >= 1.1.2.0,
163 tagged,
164 tagged,
tests/DataFamilies/Encoders.hs−4
@@ -142,8 +142,6 @@ thGADTParseJSONDefault = $(mkParseJSON defaultOptions 'GADT)
142-- Generic encoders/decoders
142-- Generic encoders/decoders
143--------------------------------------------------------------------------------
143--------------------------------------------------------------------------------
144
144
145−#if __GLASGOW_HASKELL__ >= 706
146−
147-- Nullary
145-- Nullary
148
146
149gNullaryToJSONString :: Nullary Int -> Value
147gNullaryToJSONString :: Nullary Int -> Value
@@ -236,5 +234,3 @@ gApproxToEncodingDefault = genericToEncoding defaultOptions
236
234
237gApproxParseJSONDefault :: Value -> Parser (Approx String)
235gApproxParseJSONDefault :: Value -> Parser (Approx String)
238gApproxParseJSONDefault = genericParseJSON defaultOptions
236gApproxParseJSONDefault = genericParseJSON defaultOptions
239−
240−#endif
tests/DataFamilies/Properties.hs−4
@@ -79,9 +79,6 @@ tests = testGroup "data families" [
79 ]
79 ]
80 ]
80 ]
81
81
82−-- We only test generic instances for GHC 7.6 and higher because GHC 7.4 has
83−-- a bug concerning generics and data families
84−#if __GLASGOW_HASKELL__ >= 706
85 , testGroup "generics" [
82 , testGroup "generics" [
86 testGroup "toJSON" [
83 testGroup "toJSON" [
87 testGroup "Nullary" [
84 testGroup "Nullary" [
@@ -138,5 +135,4 @@ tests = testGroup "data families" [
138 gSomeTypeToEncodingObjectWithSingleField
135 gSomeTypeToEncodingObjectWithSingleField
139 ]
136 ]
140 ]
137 ]
141−#endif
142 ]
138 ]
tests/DataFamilies/Types.hs+10−13
@@ -1,19 +1,18 @@
1+-- DataKinds is needed for deriveAll0 calls on GHC 8
1−{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE StandaloneDeriving #-}
6{-# LANGUAGE StandaloneDeriving #-}
6{-# LANGUAGE DeriveGeneric #-}
7{-# LANGUAGE DeriveGeneric #-}
8+{-# LANGUAGE TemplateHaskell #-}
7{-# LANGUAGE TypeFamilies #-}
9{-# LANGUAGE TypeFamilies #-}
8
10
9module DataFamilies.Types where
11module DataFamilies.Types where
10
12
13+import Generics.Deriving.TH (deriveAll0)
11import Types (ApproxEq(..))
14import Types (ApproxEq(..))
12
15
13−#if __GLASGOW_HASKELL__ >= 706
14−import GHC.Generics
15−#endif
16−
17data family Nullary a
16data family Nullary a
18data instance Nullary Int = C1 | C2 | C3 deriving (Eq, Show)
17data instance Nullary Int = C1 | C2 | C3 deriving (Eq, Show)
19data instance Nullary Char = C4 deriving (Eq, Show)
18data instance Nullary Char = C4 deriving (Eq, Show)
@@ -41,12 +40,10 @@ data instance GADT a where
41deriving instance Eq (GADT a)
40deriving instance Eq (GADT a)
42deriving instance Show (GADT a)
41deriving instance Show (GADT a)
43
42
44−-- We only derive instances for GHC 7.6 and higher because GHC 7.4 has a bug
43+-- We use generic-deriving to be able to derive Generic instances for
45−-- concerning generics and data families
44+-- data families on GHC 7.4.
46
45
47−#if __GLASGOW_HASKELL__ >= 706
46+$(deriveAll0 'C1)
48−deriving instance Generic (Nullary Int)
47+$(deriveAll0 'C4)
49−deriving instance Generic (Nullary Char)
48+$(deriveAll0 'Approx)
50−deriving instance Generic (SomeType c () a)
49+$(deriveAll0 'Nullary)
51−deriving instance Generic (Approx a)
52−#endif