Hi,
I'd like to be able to use randomIO, but I'm working within the
context of STM. Is there a way to get these working together happily?
For now, I guess I could kludgingly use unsafePerformIO inside STM
(it's the other way around that's not allowed, right?), but I would
need to be sure it does
On 1/12/07, Chad Scherrer <[EMAIL PROTECTED]> wrote:
Hi,
I'd like to be able to use randomIO, but I'm working within the
context of STM. Is there a way to get these working together happily?
For now, I guess I could kludgingly use unsafePerformIO inside STM
(it's the other way around that's not
On Jan 12, 2007, at 10:58 AM, Chad Scherrer wrote:
Hi,
I'd like to be able to use randomIO, but I'm working within the
context of STM. Is there a way to get these working together happily?
For now, I guess I could kludgingly use unsafePerformIO inside STM
(it's the other way around that's not
On Fri, 12 Jan 2007, Robert Dockins wrote:
> Humm... I'd actually suggest you stop trying to break the rules, and use the
> portion of the random interface that doesn't require IO. You can pretty
> easily wrap a StdGen using StateT, and write your stuff in the monad (StateT
> StdGen STM).
>
> O
Wow, lots of great ideas. Thanks, guys.
Lemmih,
I worry about the uncertainty in the semantics that seems to be
introduced by the unsafe stuff. But I actually hadn't noticed
GHC.Conc.unsafeIOToSTM before, so it's good to know it's there.
Rich,
Even if I use randomIO outside the STM code, I don't
On 1/12/07, Chad Scherrer <[EMAIL PROTECTED]> wrote:
Even if I use randomIO outside the STM code, I don't know of a (safe)
way to bring it in.
Define your STM action to be (Int -> STM s). Generate the random
number and then pass it in:
mySTM :: Int -> STM a
mySTM n = do { ... }
To use it:
do
On 1/12/07, Rich Neswold <[EMAIL PROTECTED]> wrote:
On 1/12/07, Chad Scherrer <[EMAIL PROTECTED]> wrote:
> Even if I use randomIO outside the STM code, I don't know of a (safe)
> way to bring it in.
Define your STM action to be (Int -> STM s). Generate the random
number and then pass it in:
myS
> Rather than having a separate thread computing the random numbers
> using IO, why not just stick an StdGen in a TVar and write a function
> like:
>
> type RandomVar = TVar StdGen
>
> rnd :: RandomVar -> STM a
> rnd var = do
> g <- readTVar var
> let (r,g') = random g
> writeTVar var g'
> re
On Sat, Jan 13, 2007 at 01:49:36PM +1000, Matthew Brecknell wrote:
> > Rather than having a separate thread computing the random numbers
> > using IO, why not just stick an StdGen in a TVar and write a function
> > like:
> >
> > type RandomVar = TVar StdGen
> >
> > rnd :: RandomVar -> STM a
> > r