`Random` instances for `Ratio`
- Dominant language
- Haskell
- Stars
- 59
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
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:
```haskell
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`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.