[Haskell-cafe] How to use randomized algorithm within the implementation of pure data structures?

Hiromi ISHII konn.jinro at gmail.com
Sat Nov 1 10:28:57 UTC 2014

Hi Bardur,

> You can just use the State monad to thread the StdGen around and
> "update" it when you need to. You can get a pure interface by hiding
> away the runState behind a function:

Thank you for your rapid response!
Unfortunately, I didn't describe my problem accurately.

This approach (or using MonadRandom) to pass around random generator with Monad,
works fine when it's just enough to feed generator to the algorithm.

But my situation is slightly different: random generator has to be passed around to implement
the instance method for `Num`, so it can't take random generator as its argument.
So I need some way to hide random generator from function type signatures.

Fortunately, your response suggested me the alternative approach: converting the data-type
into continuation-passing style. This should work fine when we just do some operations on
data-type, but we have to feed the generator when we want to inspect its value, so it's not
sufficient, though...

-- Hiromi ISHII
konn.jinro at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141101/ec3d95b6/attachment.sig>

More information about the Haskell-Cafe mailing list