ST monad

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ST monad

Bulat Ziganshin
Hello

the following code can't go through typechecking. can anyone help me
to fix it or, better, let me know what i need to read to fix it myself? :)

import Control.Monad.ST
import Data.Array.ST
main = print $ runST $
           do arr <- newArray (1,10) 127
              a <- readArray arr 1
              writeArray arr 1 216
              b <- readArray arr 1
              return (a,b)


PS: error message is

b.hs:4:15:
    Inferred type is less polymorphic than expected
      Quantified type variable `s' escapes
      Expected type: ST s a -> b
      Inferred type: (forall s1. ST s1 a) -> a
    In the first argument of `($)', namely `runST'
    In the second argument of `($)', namely
        `runST
         $ (do
              arr <- newArray (1, 10) 127
              a <- readArray arr 1
              writeArray arr 1 216
              b <- readArray arr 1
              return (a, b))'

 

--
Best regards,
 Bulat                          mailto:[hidden email]



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe