Search code examples
haskellquickcheck

How do I make BigFloat an instance of Arbitrary (for QuickCheck)?


The numbers package has the BigFloat type.

QuickCheck has the Arbitrary typeclass.

Because Double is an instance of Arbitrary, I can already do this:

sample (arbitrary :: Gen Double)

But I can't do this because BigFloat e isn't an instance of Arbitrary:

sample (arbitrary :: Gen (BigFloat Prec10))

How do I make BigFloat e an instance of Arbitrary?

Update. I'd love some additional information. See the comment in the bounty.


Solution

  • Posting the answer from the comments as a community-wiki answer:

    Something like:

    instance Epsilon e => Arbitrary (BigFloat e) where arbitrary = fromRational <$> arbitrary