<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<br><br>Why do I need a 'do' in the code below?<br><br>Michael<br><br>==================<br><br>import System.Random<br><br>rollDice :: IO Int<br>rollDice = getStdRandom (randomR (1,6))<br><br>rollNDice :: Int -> [IO Int]<br>rollNDice 0 = []<br>rollNDice n = rollDice : rollNDice (n-1)<br><br>=================<br><br>[michael@localhost ~]$ ghci rnd0<br>GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help<br>Loading package ghc-prim ... linking ... done.<br>Loading package integer ... linking ... done.<br>Loading package base ... linking ... done.<br>[1 of 1] Compiling Main ( rnd0.hs, interpreted )<br>Ok, modules loaded: Main.<br>*Main> rollDice<br>Loading package old-locale-1.0.0.1 ... linking ... done.<br>Loading package old-time-1.0.0.1 ... linking ...
done.<br>Loading package random-1.0.0.1 ... linking ... done.<br>6<br>*Main> rollDice<br>3<br>*Main> rollNDice 3<br><br><interactive>:1:0:<br> No instance for (Show (IO Int))<br> arising from a use of `print' at <interactive>:1:0-10<br> Possible fix: add an instance declaration for (Show (IO Int))<br> In a stmt of a 'do' expression: print it<br>*Main> <br><br></td></tr></table><br>