2
votes

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.

1
Something like instance Epsilon e => Arbitrary (BigFloat e) where arbitrary = fromRational <$> arbitrary should do it. - user2407038
Never depend on Arbitrary instances giving any particularly nice statistical distributions. They tend to be designed based on what their authors think will be most helpful for testing, rather than any theoretical considerations. - dfeuer
Also, orphan instances are kind of evil, so it's usually best to make an instance for a newtype instead. - dfeuer

1 Answers

1
votes

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

Something like:

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