You have to fix the type of 1 and 6, e.g. by writing<div><br></div><div>x &lt;- randomRIO (1, 6) :: IO Int</div><div><br></div><div>or</div><div><br></div><div>x &lt;- randomRIO (1, 6 :: Int)</div><div><br></div><div> GHCi defaults integral numbers to Int, that&#39;s why it works there.<br>
<br><div class="gmail_quote">On 24 July 2010 21:36, michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">This works:<br><br>Prelude System.Random&gt; do { randomRIO (1,6) &gt;&gt;= (\x -&gt; putStrLn $ &quot;Value = &quot; ++ show x) }<br>
Value = 5<br><br>So does this:<br><br>Prelude System.Random&gt; do { x &lt;- randomRIO (1,6); putStrLn $ &quot;Value = &quot; ++ show x }<br>Value = 2<br><br>But not this:<br><br>1 import Control.Monad<br>2 import System.Random<br>
3<br>4 foo :: IO ()<br>5 foo = do<br>6   x &lt;- randomRIO (1,6)<br>7   putStrLn $ &quot;Value = &quot; ++ show x<br><br><br>foo.hs:6:18:<br>    Ambiguous type variable `t&#39; in the constraints:<br>      `Num t&#39; arising from the literal `1&#39; at foo.hs:6:18<br>
      `Random t&#39; arising from a use of `randomRIO&#39; at foo.hs:6:7-21<br>    Probable fix: add a type signature that fixes these type variable(s)<br>Failed, modules loaded:
 none.<br>Prelude System.Random&gt; <br><br>Or this:<br><br>1 import Control.Monad<br>2 import System.Random<br>3<br>4 foo :: IO ()<br>5 foo = randomRIO (1,6) &gt;&gt;= (\x -&gt; putStrLn $ &quot;Value = &quot; ++ show x)<br>
<br><br>foo.hs:5:17:<br>    Ambiguous type variable `t&#39; in the constraints:<br>      `Num t&#39; arising from the literal `1&#39; at foo.hs:5:17<br>      `Random t&#39; arising from a use of `randomRIO&#39; at foo.hs:5:6-20<br>
    Probable fix: add a type signature that fixes these type variable(s)<br>Failed, modules loaded: none.<br><br><br>How to fix?<br><br>Michael<br><br><br><br><br><br></td></tr></tbody></table><br>

      <br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>