[Haskell-cafe] Re: ANNOUNCE: protocol-buffers-0.2.9 for Haskell
is ready
Bulat Ziganshin
bulat.ziganshin at gmail.com
Mon Sep 22 08:15:50 EDT 2008
Hello Chris,
Monday, September 22, 2008, 2:48:16 PM, you wrote:
> used a very unreliable trick. And the "use castToSTUArray" suggested
> alternative is a really poor one since I am not using arrays at all.
castToSTUArray does the same as your code, only in ST monad so you can
skip unsafePerformIO trick
if you dn't know, ST is a subset of IO monad with a limited set of
operations guaranteed to not have side-effects. so,
cvt x = unsafePerformIO $
do alloca $ \place -> do
poke place x
peek place
and
cvt x = runST $
do place <- newArray (0,1)
writeArray place 0 x
readArray place 0
generates almost the same code (the only difference is kind of memory
allocated)
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list