[Haskell-cafe] Generating random tuples
Daniel Fischer
daniel.is.fischer at web.de
Mon Nov 1 15:09:47 EDT 2010
On Monday 01 November 2010 19:55:22, Nick Bowler wrote:
> On 2010-11-01 19:18 +0100, Jacek Generowicz wrote:
> > I'm toying with generating random objects (for example tuples) and
> > started wondering what pearls of wisdom Cafe might have on the matter.
> > Two obvious points (relating to my toy code, shown below) are
> >
> > 1) The meaning of the limits required by randomR is not obvious for
> > types such as tuples (you could come up with some definition, but it
> > wouldn't be unique: how would you allow for different ones?[*]; you
> > might decide that having such limits is nonsensical and not want to
> > provide a randomR: would you then leave it undefinded?).
>
> Indeed, the Random class has a fairly narrow "everything fits on the
> real line" view of the world: not only is the talk about closed
> intervals ambiguous in general, but so is the talk about uniform
> distributions on those intervals. That being said, there is an Ord
> instance for tuples (a lexicographic ordering) and for this case I think
> it would make the most sense to use that: select an element from the set
> { x : lo <= x <= hi }
Really bad for
lo, hi :: (Int,Integer)
lo = (0,0)
hi = (3,4)
the product (partial) order seems much better to me.
More information about the Haskell-Cafe
mailing list