[Haskell-cafe] How i use GHC.Word.Word8 wit Int ?

spoon at killersmurf.com spoon at killersmurf.com
Wed May 20 07:46:06 EDT 2009


While just writing 33 instead of length [1..33] saves an awful lot of
bother, the function you'd probably want in similar circumstances is
`fromIntegral`

See the Prelude.

Also, you can use Data.ByteString.head instead of unpack and then
Data.List.head

rollDice :: Word8 -> IO Word8
rollDice n = do
    bracket (openFile "/dev/random" ReadMode) hClose
            (\hd -> do v <- fmap B.head $ B.hGet hd 1
                       return $ (v `mod` n) + 1)


More information about the Haskell-Cafe mailing list