[Haskell-cafe] Fun with the ST monad

Sterling Clover s.clover at gmail.com
Fri Feb 25 03:55:14 CET 2011


On Feb 24, 2011, at 3:45 PM, Andrew Coppin wrote:

> OK, so I had a function that looks like
> 
>  transform :: [Word8] -> [Word16]
> 
> It works nicely, but I'd like to use mutable state inside. No problem! Use the ST monad. Something like
> 
>  transform :: [Word8] -> [Word16]
>  transform xs = runST (work xs)
>    where
>      work :: [Word8] -> ST s [Word16]
> 
> Ah, yes, well there is one *small* problem... If you do that, the function becomes too strict.

unsafeInterleaveST?

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad-ST.html#v:unsafeInterleaveST

--Sterl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110224/e9bf3950/attachment-0001.htm>


More information about the Haskell-Cafe mailing list