haskell / mwc-random

A very fast Haskell library for generating high quality pseudo-random numbers.
http://hackage.haskell.org/package/mwc-random
BSD 2-Clause "Simplified" License
54 stars 25 forks source link

withSystemRandom has an unsafe type signature #61

Closed mat8913 closed 4 years ago

mat8913 commented 6 years ago

For example, it allows STRefs to escape.

Shimuuar commented 4 years ago

Indeed

import Control.Monad
import System.Random.MWC
import Data.STRef

go :: IO ()
go = do
  ref <- withSystemRandom $ \_ -> newSTRef (1 :: Int)
  (print <=< withSystemRandom) $ const $ do
    modifySTRef ref succ
    readSTRef ref
  (print <=< withSystemRandom) $ const $ do
    modifySTRef ref succ
    readSTRef ref

I think only way to fix it is to provide versins specifically to ST and deprecate withSystemRandom