[Haskell-cafe] REALLY simple STRef examples

tpledger at ihug.co.nz tpledger at ihug.co.nz
Wed Jul 19 19:33:11 EDT 2006

Chad Scherrer wrote:
> x = runST $ return 1
> y = runST $ do {r <- newSTRef 1; readSTRef r}
> Neither of these works in ghci

x = runST (return 1)

y = runST (do {r <- newSTRef 1; readSTRef r})

The escaping s is something to do with rank 2 polymorphism. 
(Search for "rank" in the ghc user guide, for example.)

The hassle is that runST must always be applied to an
argument (e.g. not passed to ($)), and a benefit is that
you're protected from using an STRef you created in the
context of one runST, in the context of another runST.


More information about the Haskell-Cafe mailing list