On May 19, 2009, at 01:07 , z_axis wrote:
rollDice_t n = do hd <- openFile "/dev/random" ReadMode v <- B.hGet hd 1 return (v `mod` n) + 1No instance for (Integral B.ByteString)
You can't just read a binary string and have it interpreted as a number; you want to use Data.Binary to extract an Int (or whatever) from the ByteString. The same would apply with legacy Strings; in Haskell, String, ByteString, and Int are distinct types and there is no automatic casting. In fact I'm not quite sure why you thought that should work; even Perl would make you unpack(), and C would require you to use an appropriately-aligned buffer and unsafely cast the (char *) to an (int *).
-- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
PGP.sig
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe