git.iko.soy/typeable/generic-arbitrary
on master help sign in
limitation demo
commitf84e0510eff3c31ec5937ca0fd3349b1a66bd02a authorAleksey Uymanov <s9gf4ult@gmail.com> dateFri 5 Aug 2022, 12:06 (4 years ago) parent114d77b
3 files changed+33−2
generic-arbitrary.cabal+2−1 src/Test/QuickCheck/Arbitrary/Generic.hs+1−1 test/LimitationDemo.hs+30
generic-arbitrary.cabal+2−1
@@ -67,7 +67,8 @@ test-suite test
6767 , tasty-discover
6868 , tasty-hunit
6969 , tasty-quickcheck
70− other-modules: NoTypecheckTest
70+ other-modules: LimitationDemo
71+ , NoTypecheckTest
7172 , RecursiveTest
7273 default-extensions: AllowAmbiguousTypes
7374 , CPP
src/Test/QuickCheck/Arbitrary/Generic.hs+1−1
@@ -53,7 +53,7 @@ newtype GenericArbitrary a = GenericArbitrary { unGenericArbitrary :: a }
5353
5454instance
5555 ( Generic a,
56− GArbitrary a (Rep a) 'True,
56+ GArbitrary a (Rep a) some,
5757 RecursivelyShrink (Rep a),
5858 GSubterms (Rep a) a
5959 ) => 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