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 = d
2009/5/20 Bernie Pope :
> Oh right. I didn't see your proposal (did it get sent to the list?).
Yes, I just push the Replay button, not the
> Sorry for the confusion.
It's my fault, sorry.
lee
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http
On Wed, May 20, 2009 at 3:40 AM, z_a...@163.com wrote:
> Hi, friends
>
> rollDice :: Word8 -> IO Word8
> rollDice n = do
> bracket (openFile "/dev/random" ReadMode) (hClose)
> (\hd -> do v <- fmap B.unpack (B.hGet hd 1)
> let v1 = Data.List.head v
> retu
2009/5/20 z_a...@163.com :
> Hi, friends
>
> rollDice :: Word8 -> IO Word8
> rollDice n = do
> bracket (openFile "/dev/random" ReadMode) (hClose)
> (\hd -> do v <- fmap B.unpack (B.hGet hd 1)
> let v1 = Data.List.head v
> return $ (v1 `mod` n) + 1)
>
On Wed, May 20, 2009 at 08:40:15AM +0800, z_a...@163.com wrote:
> I know "length [1..33]" is Int not Word8, but Word8 is enough here.
Just saying '33' is enough here. :)
--
Felipe.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskel
Hi, friends
rollDice :: Word8 -> IO Word8
rollDice n = do
bracket (openFile "/dev/random" ReadMode) (hClose)
(\hd -> do v <- fmap B.unpack (B.hGet hd 1)
let v1 = Data.List.head v
return $ (v1 `mod` n) + 1)
.
blueIdx <- rollDice $ length [1..33]