-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
There is currently no instances for Ratio
data type that can give us random values
Edit: - It looks like we are in a agreement that Uniform
and UniformRange
instances are not possible for Ratio
. Question then is, should we add a Random
instance, which doesn't really promise uniformity?
I can see a reasonable Uniform
instance for integral types, which excludes the zero denominator:
instance (Integral a, Uniform a) => Uniform (Ratio a) where
uniformM g = do
n <- uniformM g
let notZero = do
d <- uniformM g
if d == 0 then notZero else pure d
(n %) <$> notZero
An efficient version for UniformRange
needs some thought.
Note that neither Uniform
, nor UniformRange
would be able to generate Rational
. This means that we can attempt and cook up such instance for Random
Metadata
Metadata
Assignees
Labels
No labels