typeable / generic-arbitrary Goto Github PK
View Code? Open in Web Editor NEWGeneric method implementations for Arbitrary
License: MIT License
Generic method implementations for Arbitrary
License: MIT License
I tried the following:
data Expr
= Lit Int
| Add Expr Expr
| Mul Expr Expr
deriving (Eq, Show, Generic)
instance Arbitrary Expr where
arbitrary = genericArbitrary
shrink = genericShrink
> generate arbitrary :: IO Expr
This usually never finishes, generating an infinitely large expression.
It did take a while to figure out that the arbitrary instance generates an infinite value rather than my other code getting stuck in an infinite loop.
I then tried using quickcheck-arbitrary-adt
instead and my problem was solved. I'm not sure what the differences between the packages are.
Cheers! Yair
It's missing from https://hackage.haskell.org/package/generic-arbitrary
GHCup uses generic-arbitrary: https://gitlab.haskell.org/haskell/ghcup-hs/-/blob/master/test/GHCup/ArbitraryTypes.hs
Since 0.2.1 the tests fail with:
Test suite ghcup-test: RUNNING...
FF
Failures:
src/Test/Aeson/Internal/RoundtripSpecs.hs:59:5:
1) GHCup.Types.JSON, JSON encoding of GHCupInfo, allows to encode values with aeson and read them back
uncaught exception: ErrorCall
Test.QuickCheck.resize: negative size
CallStack (from HasCallStack):
error, called at src/Test/QuickCheck/Gen.hs:135:22 in QuickCheck-2.14.2-a4039abb5c2bf61956f8dce1084c880ba597c6b14935be0ae502da628dbe9111:Test.QuickCheck.Gen
(after 1 test)
Exception thrown while showing test case:
Test.QuickCheck.resize: negative size
CallStack (from HasCallStack):
error, called at src/Test/QuickCheck/Gen.hs:135:22 in QuickCheck-2.14.2-a4039abb5c2bf61956f8dce1084c880ba597c6b14935be0ae502da628dbe9111:Test.QuickCheck.Gen
To rerun use: --match "/GHCup.Types.JSON/JSON encoding of GHCupInfo/allows to encode values with aeson and read them back/"
src/Test/QuickCheck/Gen.hs:135:22:
2) GHCup.Types.JSON, JSON encoding of GHCupInfo, produces the same JSON as is found in test/golden/GHCupInfo.json
uncaught exception: ErrorCall
Test.QuickCheck.resize: negative size
CallStack (from HasCallStack):
error, called at src/Test/QuickCheck/Gen.hs:135:22 in QuickCheck-2.14.2-a4039abb5c2bf61956f8dce1084c880ba597c6b14935be0ae502da628dbe9111:Test.QuickCheck.Gen
To rerun use: --match "/GHCup.Types.JSON/JSON encoding of GHCupInfo/produces the same JSON as is found in test/golden/GHCupInfo.json/"
Randomized with seed 25004185
Finished in 0.2310 seconds
2 examples, 2 failures
I'm suspecting it may be 0e2e124
Hi,
the package failing to build with GHC 9.2.1
this package is part of dependency in ghcup test suite and it causes it to fail when building/testing with GHC 9.2.1
The Logs :-
Failed to build generic-arbitrary-0.2.0.
Build log (
/home/username/.cabal/logs/ghc-9.2.1/generic-arbitrary-0.2.0-b7ba577fe184c21dde1df651e1a01fd625359d2e2adc1e72a43a5dae766cbcf6.log
):
Warning: generic-arbitrary.cabal:18:28: Packages with 'cabal-version: 1.12' or
later should specify a specific version of the Cabal spec of the form
'cabal-version: x.y'. Use 'cabal-version: 1.22'.
Configuring library for generic-arbitrary-0.2.0..
Preprocessing library for generic-arbitrary-0.2.0..
Building library for generic-arbitrary-0.2.0..
[1 of 1] Compiling Test.QuickCheck.Arbitrary.Generic ( src/Test/QuickCheck/Arbitrary/Generic.hs, dist/build/Test/QuickCheck/Arbitrary/Generic.o, dist/build/Test/QuickCheck/Arbitrary/Generic.dyn_o )
src/Test/QuickCheck/Arbitrary/Generic.hs:53:3: error:
• Non type-variable argument in the constraint: GArbitrary (Rep a)
(Use FlexibleContexts to permit this)
• In the instance declaration for ‘Arbitrary (GenericArbitrary a)’
|
53 | ( Generic a,
| ^^^^^^^^^^^^...
src/Test/QuickCheck/Arbitrary/Generic.hs:82:10: error:
• Non type-variable argument in the constraint: KnownNat (SumLen a)
(Use FlexibleContexts to permit this)
• In the instance declaration for ‘GArbitrary (a :+: b)’
|
82 | instance (GArbitrary a, GArbitrary b, KnownNat (SumLen a), KnownNat (SumLen b)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
cabal: Failed to build generic-arbitrary-0.2.0 (which is required by
test:ghcup-test from ghcup-0.1.17.4). See the build log above for details.
With a plain sum type, on GHC 9.4.1, we get ambiguous type variable errors when trying to write instance Arbitrary X where arbitrary = genericArbitrary
Apologies for the bad issue, I'll work up a reproduction soon
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.