[Haskell-cafe] Different forms for RandomT?

Roman Cheplyaka roma at ro-che.info
Thu Jul 30 18:14:37 UTC 2015

On 30/07/15 20:38, Zemyla wrote:
> Normally, a monad transformer to provide a random number generator would
> be of the form StateT g, where g is a RandomGen. But I've seen some
> libraries (like QuickCheck) define their RandomT as:
> newtype RandomT g m a = RandomT { runRandomT :: g -> m a }
> with their monadic bind operation defined as
> (RandomT m) >>= f = RandomT $ \g -> let (ga, gb) = split g in m ga >>=
> (\a -> runRandomT (f a) gb)
> and return and fail as in ReaderT.
> Can someone describe the advantages and disadvantages of doing RandomT
> this way? I mean, if your generator has a subpar split operation (and
> most do), this will obviously exacerbate any problems with it.

tf-random addresses this.

> Does it give any comparable advantages?

It doesn't introduce data dependencies. Let's say you generate a random
binary tree. With the split approach, you can take the right subtree
without evaluating the left one.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150730/ca6b1487/attachment.sig>

More information about the Haskell-Cafe mailing list