System.Random instances for tuples

Dan Burton at
Tue Apr 17 04:04:52 CEST 2012

Ever find yourself wanting to generate a tuple of random things? Instances
are trivial to write in Haskell 98:

instance (Random a, Random b) => Random (a, b) where
  randomR ((loL, loR), (hiL, hiR)) g = ((l, r), g'')
    where (l, g')  = randomR (loL, hiL) g
          (r, g'') = randomR (loR, hiR) g'
  random g = ((l, r), g'')
    where (l, g')  = random g
          (r, g'') = random g'

Can we add instances like this to System.Random in the random package?

-- Dan Burton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list