<div dir="ltr"><div>I&#39;m not exactly sure why you get the error, but the easiest way to fix it is just to type it this way:<br><br>runSimulation :: Word32 -&gt; [Int]<br>runSimulation seed = runST $ do<br>  gen &lt;- initialize (singleton seed)<br>
  whileM  (do r1 &lt;- uniformR (-1.0, 1.0 :: Double) gen<br>              if r1 &gt; 0.0 then return True else return False)<br>          (do r2 &lt;- uniformR (0, 10 :: Int) gen<br>              if r2 &gt; 5 then return r2 else return 0)<br>
<br></div>It has something to do with the forall s in runST, although I&#39;m not completely sure what.<br><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 18, 2013 at 9:18 PM, Aurimas <span dir="ltr">&lt;<a href="mailto:aurimas.anskaitis@vgtu.lt" target="_blank">aurimas.anskaitis@vgtu.lt</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have the following code which does not compile due to explicit type annotation<br>
(ST s Double). Error message says usual thing about &quot;s&quot; type variables.<br>
<br>
------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>----------------<br>
import <a href="http://Control.Monad.ST" target="_blank">Control.Monad.ST</a><br>
import System.Random.MWC (initialize, uniformR, Gen)<br>
import Control.Monad.Loops (whileM)<br>
import Data.Vector (singleton)<br>
import Data.Word(Word32)<br>
<br>
main :: IO ()<br>
main = do<br>
  print $ runSimulation 1<br>
<br>
runSimulation :: Word32 -&gt; [Int]<br>
runSimulation seed = runST $ do<br>
  gen &lt;- initialize (singleton seed)<br>
  whileM  (do r1 &lt;- uniformR (-1.0, 1.0) gen :: ST s Double -- does not compile due to this<br>
              if r1 &gt; 0.0 then return True else return False)<br>
          (do r2 &lt;- uniformR (0, 10) gen<br>
              if r2 &gt; 5 then return r2 else return 0)<br>
------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
<br>
if I rewrite runSimulation like this (below), everything is OK.<br>
<br>
------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
runSimulation :: Word32 -&gt; [Int]<br>
runSimulation seed = runST $ do<br>
  gen &lt;- initialize (singleton seed)<br>
  whileM  (do r1 &lt;- tempFun gen<br>
              if r1 &gt; 0.0 then return True else return False)<br>
          (do r2 &lt;- uniformR (0, 10) gen<br>
              if r2 &gt; 5 then return r2 else return 0)<br>
    where tempFun :: Gen s -&gt; ST s Double    -- this line automatically provides required type annotation<br>
          tempFun g = uniformR (-1.0, 1.0) g<br>
------------------------------<u></u>------------------------------<u></u>------------------------------<u></u>---------------<br>
<br>
Ca somebody explain what&#39;s wrong with the first version?<br>
<br>
Best Regards,<br>
Aurimas<br>
<br>
<br>
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>