System.Random instances for tuples

Dan Burton danburton.email at gmail.com
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: <http://www.haskell.org/pipermail/libraries/attachments/20120416/65845009/attachment.htm>


More information about the Libraries mailing list