@@ -11,24 +11,29 @@ module Instances () where
1111import Prelude ()
1212import Prelude.Compat
1313
14−import Control.Applicative (Const(..), empty)
14+import Control.Applicative (empty)
1515import Control.Monad
1616import Data.Aeson.Types
1717import Data.Function (on)
1818import Data.Functor.Compose (Compose (..))
19−import Data.Functor.Identity (Identity (..))
20−import Data.List.NonEmpty (NonEmpty(..))
2119import Data.Proxy (Proxy(..))
2220import Data.Tagged (Tagged(..))
2321import Data.Time (ZonedTime(..), TimeZone(..))
2422import Data.Time.Clock (UTCTime(..))
25−import Data.Version
2623import Functions
27−import Test.QuickCheck (Arbitrary(..), getNonNegative, elements, listOf1, oneof, resize)
24+import Test.QuickCheck (Arbitrary(..), elements, oneof)
2825import Types
2926import qualified Data.DList as DList
3027import qualified Data.HashMap.Strict as HM
3128
29+#if !MIN_VERSION_QuickCheck(2,9,0)
30+import Control.Applicative (Const(..))
31+import Data.List.NonEmpty (NonEmpty(..))
32+import Data.Functor.Identity (Identity (..))
33+import Data.Version
34+import Test.QuickCheck (getNonNegative, listOf1, resize)
35+#endif
36+
3237import Data.Orphans ()
3338import Test.QuickCheck.Instances ()
3439#if MIN_VERSION_base(4,7,0)
@@ -172,21 +177,11 @@ instance ApproxEq Char where
172177instance (ApproxEq a) => ApproxEq [a] where
173178 a =~ b = length a == length b && all (uncurry (=~)) (zip a b)
174179
175−instance Arbitrary Version where
176− arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
177−
178−instance Arbitrary a => Arbitrary (NonEmpty a) where
179− arbitrary = (:|) <$> arbitrary <*> arbitrary
180−
181180-- Version tags are deprecated, so we avoid using them in the Arbitrary
182181-- instance. However, the recommended constructor 'makeVersion' is not
183182-- exported by "Data.Version" until base-4.8.0.0. For previous versions,
184183-- a definition is given below.
185184
186−#if !MIN_VERSION_base(4,8,0)
187−makeVersion :: [Int] -> Version
188−makeVersion b = Version b []
189−#endif
190185
191186#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
192187instance Arbitrary Natural where
@@ -199,15 +194,27 @@ instance Arbitrary (Proxy a) where
199194instance Arbitrary b => Arbitrary (Tagged a b) where
200195 arbitrary = Tagged <$> arbitrary
201196
197+instance Arbitrary a => Arbitrary (DList.DList a) where
198+ arbitrary = DList.fromList <$> arbitrary
199+
200+instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where
201+ arbitrary = Compose <$> arbitrary
202+
203+#if !MIN_VERSION_QuickCheck(2,9,0)
202204instance Arbitrary a => Arbitrary (Const a b) where
203205 arbitrary = Const <$> arbitrary
204206
205−instance Arbitrary a => Arbitrary (DList.DList a) where
206− arbitrary = DList.fromList <$> arbitrary
207+instance Arbitrary a => Arbitrary (NonEmpty a) where
208+ arbitrary = (:|) <$> arbitrary <*> arbitrary
209+
210+instance Arbitrary Version where
211+ arbitrary = makeVersion . fmap getNonNegative <$> resize 4 (listOf1 arbitrary)
212+
213+#if !MIN_VERSION_base(4,8,0)
214+makeVersion :: [Int] -> Version
215+makeVersion b = Version b []
216+#endif
207217
208−-- would like to have -- https://github.com/nick8325/quickcheck/issues/73
209218instance Arbitrary a => Arbitrary (Identity a) where
210219 arbitrary = Identity <$> arbitrary
211−
212−instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where
213− arbitrary = Compose <$> arbitrary
220+#endif