Closed safareli closed 4 years ago
That seems similar to using a state monad for randomness, State RandomSeed
. It's a perfectly reasonable approach 99.99% of the time. The advantage of the current Gen
is that it is a little more lazy. Consider generating a pair:
(,) <$> genA <*> genB :: Gen (A, B)
Now suppose only B
gets used. With a State
-based generator, you have to run genA
to be able to run genB
. With a splitting-based generator like Gen
, genB
can be run independently. This kind of laziness fundamentally requires splitting "overeagerly". It is not a problem in practice because (1) the laws hold when a Gen
is viewed as a probability distribution, and (2) it's uncommon to bind generators that do nothing to the point that the redundant splitting becomes a problem for performance.
thanks
Was there an attempt of implementing Gen using some Free like datatype which is "mart" and avoids split of the seed when encountering the case like
return x >>= f
?