[Haskell-beginners] Type inference in ST monad?

Aurimas aurimas.anskaitis at vgtu.lt
Mon Aug 19 07:36:10 CEST 2013


On 08/19/2013 05:04 AM, David McBride wrote:
> I'm not exactly sure why you get the error, but the easiest way to fix 
> it is just to type it this way:
>
> runSimulation :: Word32 -> [Int]
> runSimulation seed = runST $ do
>   gen <- initialize (singleton seed)
>   whileM  (do r1 <- uniformR (-1.0, 1.0 :: Double) gen
>               if r1 > 0.0 then return True else return False)
>           (do r2 <- uniformR (0, 10 :: Int) gen
>               if r2 > 5 then return r2 else return 0)
>
> It has something to do with the forall s in runST, although I'm not 
> completely sure what.
>
Thanks, this is clearly the most easy way to fix the problem. But the 
question remains - why the line
"do r1 <- uniformR (-1.0, 1.0 :: Double) gen"    cannot be annotated 
with ST s Double?




More information about the Beginners mailing list