<div dir="ltr"><div><div><div>I have to produce a crypto random UUID. <br><br>I haven't found simple examples. and I used the one from hre (see type CRand) <a href="http://hackage.haskell.org/package/monadcryptorandom-0.7.0/docs/Control-Monad-CryptoRandom.html#v:getCRandomR">http://hackage.haskell.org/package/monadcryptorandom-0.7.0/docs/Control-Monad-CryptoRandom.html#v:getCRandomR</a> <br><br>My attempt is the following:<br><br>cryptoRandomUUID :: IO UUID.UUID<br>cryptoRandomUUID = do<br>  g <- newGenIO:: IO SystemRandom<br>  case runCRand impl g of<br>    Left err -> throwIO err<br>    Right (v, g') -> return v<br><br>  where impl = do<br>          w1 <- getCRandom<br>          w2 <- getCRandom<br>          w3 <- getCRandom<br>          w4 <- getCRandom<br>          return $ UUID.fromWords w1 w2 w3 w4<br><br></div><div>...but the compilation fails miserably with:<br><br>    • Ambiguous type variable ‘e0’ arising from a use of ‘runCRand’<br>      prevents the constraint ‘(ContainsGenError e0)’ from being solved.<br>      Relevant bindings include<br>        impl :: CRandT<br>                  SystemRandom e0 Data.Functor.Identity.Identity UUID.UUID<br>          (bound at src/Party.hs:75:9)<br>      Probable fix: use a type annotation to specify what ‘e0’ should be.<br>      These potential instance exist:<br>        instance ContainsGenError GenError<br>          -- Defined in ‘Control.Monad.CryptoRandom’<br>    • In the expression: runCRand impl g<br>      In a stmt of a 'do' block:<br>        case runCRand impl g of {<br>          Left err -> throwIO err<br>          Right (v, g') -> return v }<br>      In the expression:<br>        do { g <- newGenIO :: IO SystemRandom;<br>             case runCRand impl g of {<br>               Left err -> throwIO err<br>               Right (v, g') -> return v } }<br>      ...<br><br></div><div>What's the problem here?<br>Are there some good examples for generating crypto-randoms?<br><br></div></div></div>Thanks!<br></div>