<div dir="ltr"><div>Thanks! It works. <br><br></div>Why is this a "quick and dirty" fix and what would be the "clean" fix?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 12, 2016 at 8:15 PM, David McBride <span dir="ltr"><<a href="mailto:toad3k@gmail.com" target="_blank">toad3k@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>The problem is with<br></div><span class=""> Left err -> throwIO err<br><br></span></div>Because of the type of 'runCRand', we know err is an instance of ContainsGenError e0, but which one? We need a concrete error type before we can run this code. Looking at the docs there seems to be only one instance of ContainsGenError, GenError, so a quick an dirty solution would be to change it to<br><br></div> Left err -> throwIO (err :: GenError) -- should work<br><br></div><div>But keep in mind, if there were any other ContainsGenError instances, like from an external library that is adding a new type of random generator to this library that fails in a new way, you would not be catching that.<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Dec 12, 2016 at 12:52 PM, Ovidiu Deac <span dir="ltr"><<a href="mailto:ovidiudeac@gmail.com" target="_blank">ovidiudeac@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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" target="_blank">http://hackage.haskell.org/pac<wbr>kage/monadcryptorandom-0.7.0/<wbr>docs/Control-Monad-CryptoRando<wbr>m.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>
<br></div></div>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>