[Haskell-cafe] How to use Data.ByteString ?

z_axis z_axis at 163.com
Tue May 19 01:07:41 EDT 2009


Hi, friends
the following function works well
rollDice n = getStdRandom (randomR (1,n)) :: IO Int

now i want to use /dev/random to produce better random number, but it doesnot work
rollDice_t n = do
    hd <- openFile "/dev/random" ReadMode
    v <-  B.hGet hd 1
    return (v `mod` n) + 1

 No instance for (Integral B.ByteString)
      arising from a use of `mod' at Money.hs:15:12-20
    Possible fix:
      add an instance declaration for (Integral B.ByteString)
    In the first argument of `return', namely `(v `mod` n)'
    In the first argument of `(+)', namely `return (v `mod` n)'
    In the expression: return (v `mod` n) + 1

then how to use the ByteString properly ?

Sincerely!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090519/6b3fae95/attachment.html


More information about the Haskell-Cafe mailing list