This discussion has already popped up thanks to @Shimuuar
uniformR says generate all possible values with equal probability. Integer works just fine with this. But uniform? No way! There's infinite number of integers
It would make absolute sense to split number generation into two(three) groups:
- Bounded:
Int, Word, etc:
- Unbounded:
Integer, Natural
- Potentially also:
Float and Double (CFloat and CDouble too of course)
Reasons I consider including floating point numbers here instead of with fixed width integral types because:
- There are whole lot of binary representations of floating numbers that aren't really valid:
NaN,+/-0 and +/-Infinity
- Floating point numbers don't have
Bounded instance
What are our options:
-
Leave it broken as it is now in Random and in Variate classes.
-
Introduce RandomR for all types that can be generated, while using Random only for things that has bounds:
class RandomR a where
randomRM :: MonadRandom g m => (a, a) -> g -> m a
randomR :: NoSplitGen g => (a, a) -> g -> (a, g)
randomR r g = runStateGen g (genRandomR r)
class (Bounded a, RandomR a) => Random a where
randomM :: MonadRandom g m => g -> m a
randomM = randomRM (minBound, maxBound)
random :: NoSplitGen g => g -> (a, g)
random g = runStateGen g genRandom
This will be a breaking change for users that are relying on random to generate floating point numbers and unbounded integral types.
Conceptually though, I think this is a good distinction to have.
Thoughts?
This discussion has already popped up thanks to @Shimuuar
It would make absolute sense to split number generation into two(three) groups:
Int,Word, etc:Integer,NaturalFloatandDouble(CFloatandCDoubletoo of course)Reasons I consider including floating point numbers here instead of with fixed width integral types because:
NaN,+/-0and+/-InfinityBoundedinstanceWhat are our options:
Leave it broken as it is now in
Randomand inVariateclasses.Introduce
RandomRfor all types that can be generated, while usingRandomonly for things that has bounds:This will be a breaking change for users that are relying on
randomto generate floating point numbers and unbounded integral types.Conceptually though, I think this is a good distinction to have.
Thoughts?