on master help sign in
Use generic-deriving to test data family generics on GHC 7.4
commitfdfbf2a6ba3d0b1369536d07c00e50e3862b89be authorAdam Bergmark <adam@bergmark.nl> dateSat 7 May 2016, 10:33 (10 years ago) parent5f93374
4 files changed+12−22
aeson.cabal+2−1 tests/DataFamilies/Encoders.hs−4 tests/DataFamilies/Properties.hs−4 tests/DataFamilies/Types.hs+10−13
aeson.cabal+2−1
@@ -155,9 +155,10 @@ test-suite tests
155155 aeson,
156156 attoparsec,
157157 base,
158− base-orphans >=0.5.3 && <0.6,
158+ base-orphans >= 0.5.3 && <0.6,
159159 bytestring,
160160 containers,
161+ generic-deriving >= 1.10 && < 1.11,
161162 ghc-prim >= 0.2,
162163 hashable >= 1.1.2.0,
163164 tagged,
tests/DataFamilies/Encoders.hs−4
@@ -142,8 +142,6 @@ thGADTParseJSONDefault = $(mkParseJSON defaultOptions 'GADT)
142142-- Generic encoders/decoders
143143--------------------------------------------------------------------------------
144144
145−#if __GLASGOW_HASKELL__ >= 706
146−
147145-- Nullary
148146
149147gNullaryToJSONString :: Nullary Int -> Value
@@ -236,5 +234,3 @@ gApproxToEncodingDefault = genericToEncoding defaultOptions
236234
237235gApproxParseJSONDefault :: Value -> Parser (Approx String)
238236gApproxParseJSONDefault = genericParseJSON defaultOptions
239−
240−#endif
tests/DataFamilies/Properties.hs−4
@@ -79,9 +79,6 @@ tests = testGroup "data families" [
7979 ]
8080 ]
8181
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
8582 , testGroup "generics" [
8683 testGroup "toJSON" [
8784 testGroup "Nullary" [
@@ -138,5 +135,4 @@ tests = testGroup "data families" [
138135 gSomeTypeToEncodingObjectWithSingleField
139136 ]
140137 ]
141−#endif
142138 ]
tests/DataFamilies/Types.hs+10−13
@@ -1,19 +1,18 @@
1−{-# LANGUAGE CPP #-}
1+-- DataKinds is needed for deriveAll0 calls on GHC 8
2+{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE FlexibleInstances #-}
34{-# LANGUAGE GADTs #-}
45{-# LANGUAGE GeneralizedNewtypeDeriving #-}
56{-# LANGUAGE StandaloneDeriving #-}
67{-# LANGUAGE DeriveGeneric #-}
8+{-# LANGUAGE TemplateHaskell #-}
79{-# LANGUAGE TypeFamilies #-}
810
911module DataFamilies.Types where
1012
13+import Generics.Deriving.TH (deriveAll0)
1114import Types (ApproxEq(..))
1215
13−#if __GLASGOW_HASKELL__ >= 706
14−import GHC.Generics
15−#endif
16−
1716data family Nullary a
1817data instance Nullary Int = C1 | C2 | C3 deriving (Eq, Show)
1918data instance Nullary Char = C4 deriving (Eq, Show)
@@ -41,12 +40,10 @@ data instance GADT a where
4140deriving instance Eq (GADT a)
4241deriving instance Show (GADT a)
4342
44−-- We only derive instances for GHC 7.6 and higher because GHC 7.4 has a bug
45−-- concerning generics and data families
43+-- We use generic-deriving to be able to derive Generic instances for
44+-- data families on GHC 7.4.
4645
47−#if __GLASGOW_HASKELL__ >= 706
48−deriving instance Generic (Nullary Int)
49−deriving instance Generic (Nullary Char)
50−deriving instance Generic (SomeType c () a)
51−deriving instance Generic (Approx a)
52−#endif
46+$(deriveAll0 'C1)
47+$(deriveAll0 'C4)
48+$(deriveAll0 'Approx)
49+$(deriveAll0 'Nullary)