git.iko.soy/typeable/generic-arbitrary
on master help sign in
limitation demo
f84e051Aleksey Uymanov
generic-arbitrary.cabal+2−1
@@ -67,7 +67,8 @@ test-suite test
67 , tasty-discover
67 , tasty-discover
68 , tasty-hunit
68 , tasty-hunit
69 , tasty-quickcheck
69 , tasty-quickcheck
70+ other-modules: LimitationDemo
70− other-modules: NoTypecheckTest
71+ , NoTypecheckTest
71 , RecursiveTest
72 , RecursiveTest
72 default-extensions: AllowAmbiguousTypes
73 default-extensions: AllowAmbiguousTypes
73 , CPP
74 , CPP
src/Test/QuickCheck/Arbitrary/Generic.hs+1−1
@@ -53,7 +53,7 @@ newtype GenericArbitrary a = GenericArbitrary { unGenericArbitrary :: a }
53
53
54instance
54instance
55 ( Generic a,
55 ( Generic a,
56− GArbitrary a (Rep a) 'True,
56+ GArbitrary a (Rep a) some,
57 RecursivelyShrink (Rep a),
57 RecursivelyShrink (Rep a),
58 GSubterms (Rep a) a
58 GSubterms (Rep a) a
59 ) => Arbitrary (GenericArbitrary a) where
59 ) => Arbitrary (GenericArbitrary a) where
test/LimitationDemo.hsnew file+30
@@ -0,0 +1,30 @@
1+{-# LANGUAGE NumDecimals #-}
2+{-# LANGUAGE DerivingStrategies #-}
3+{-# LANGUAGE DerivingVia #-}
4+{-# LANGUAGE DeriveAnyClass #-}
5+
6+module LimitationDemo where
7+
8+import Control.DeepSeq
9+import GHC.Generics (Generic)
10+import Test.QuickCheck
11+import Test.QuickCheck.Arbitrary.Generic
12+
13+-- As you can see, we have this instance generated, but it will definitely lead
14+-- to generating an infinite term (and the only term). The recursion detection
15+-- doesn't work here
16+data R1 = R1 R2
17+ deriving (Eq, Ord, Show, Generic)
18+ deriving anyclass NFData
19+ deriving Arbitrary via (GenericArbitrary R1)
20+
21+data R2 = R2 R1
22+ deriving (Eq, Ord, Show, Generic)
23+ deriving anyclass NFData
24+ deriving Arbitrary via (GenericArbitrary R2)
25+
26+-- To force the instance realy be generated
27+usage :: IO ()
28+usage = do
29+ r1 :: R1 <- generate arbitrary
30+ print r1 -- haha