[Haskell-cafe] Why do I need a 'do'?
michael rice
nowgate at yahoo.com
Wed Apr 29 21:39:37 EDT 2009
Hi,
Why do I need a 'do' in the code below?
Michael
==================
import System.Random
rollDice :: IO Int
rollDice = getStdRandom (randomR (1,6))
rollNDice :: Int -> [IO Int]
rollNDice 0 = []
rollNDice n = rollDice : rollNDice (n-1)
=================
[michael at localhost ~]$ ghci rnd0
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( rnd0.hs, interpreted )
Ok, modules loaded: Main.
*Main> rollDice
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.1 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
6
*Main> rollDice
3
*Main> rollNDice 3
<interactive>:1:0:
No instance for (Show (IO Int))
arising from a use of `print' at <interactive>:1:0-10
Possible fix: add an instance declaration for (Show (IO Int))
In a stmt of a 'do' expression: print it
*Main>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090429/27de0f03/attachment.htm
More information about the Haskell-Cafe
mailing list