System.Random instances for tuples

Yitzchak Gale gale at
Tue Apr 17 21:11:31 CEST 2012

Dan Burton wrote:
> Ever find yourself wanting to generate a tuple of random things? Instances
> are trivial to write in Haskell 98...
> Can we add instances like this to System.Random in the random package?

I'm guessing that this was left out because of its
surprising side-effect of adding strictness to the
first component: If you try to get the value of the
second component, the first one is forced.

For example, imagine that in randomR the
computation for the lower bound on the first
component is expensive or bottom, and you
only ask for the second component in the
calling code.

You would really want to use split for this. But
not much is known about how to write good
random generators with provably good splitting


More information about the Libraries mailing list