[Haskell-cafe] STM and random numbers

Lemmih lemmih at gmail.com
Fri Jan 12 11:20:39 EST 2007


On 1/12/07, Chad Scherrer <chad.scherrer at gmail.com> 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 allowed, right?), but I would
> need to be sure it doesn't get inlined.

You could use GHC.Conc.unsafeIOToSTM. Just be aware that your
transaction may be re-executed an arbitrary number of times.

-- 
Cheers,
  Lemmih


More information about the Haskell-Cafe mailing list