Proposal: Generalize the RandomGen and Random classes

Antoine Latter aslatter at gmail.com
Wed Oct 6 19:10:36 EDT 2010


On Wed, Oct 6, 2010 at 6:09 PM, Antoine Latter <aslatter at gmail.com> wrote:
>
> I guess the new class interface feels somehow off to me.
>
> As a developer, I would now say: "The function requires a random
> generator which exclusively produces Word16s" which I find oddly
> specific, and lowers the chances of me being able to use a single
> generator with disparately authored components without piles of
> newtype shims (and who know what else).
>
> Maybe a better solution would be for the RandomGen class to provide a
> multitude of 'next' functions:
>
> next :: g -> (Int, g)
> nextInt :: g -> (Int, g)
> nextInt8 :: g -> (Int8, g)
> nextInt16 :: g -> (Int16, g)
> nextInt32 :: g -> (Int32, g)
> .
> .
> .
> nextWord :: g -> (Word, g)
> nextword8 :: g -> (Word8,g)
> .
> .
> .
> nextDouble :: g -> (Double, g)
>
> The class methods other than 'next' would have a default
> implementation equivalent to the above value's Random instance.
>
> Then as a consumer of a RandomGen, I can ask for the values I want,
> and the implementation of the RandomGen can provide efficiently what
> it can.
>
> And then as a downstream developer I can benchmark like crazy to find
> the combination that works for me.
>
> Plus, I don't think this requires additional extensions.
>
> Antoine
>

All of this is predicated on specializing the random-data-consumer to
the random-data-producer being a significant performance win.

Antoine


More information about the Libraries mailing list