[Haskell-cafe] problem using ST monad

Henning Thielemann lemming at henning-thielemann.de
Sun Oct 26 06:31:43 EDT 2008


On Sat, 25 Oct 2008, Paul L wrote:

> I'm have some trouble using the ST monad, and I think
> I'm confused about its use of existential type.
>
>> {-# OPTIONS -XRankNTypes #-}
>> import Control.Monad.ST
>> import Data.Array.ST
>
> I want to implement a map function that unfold
> all ST monads in a list:
>
>> mapST :: (a -> (forall s . ST s b)) -> [a] -> [b]
>> mapST f (x:xs) = runST (f x) : mapST f xs
>> mapST f [] = []

I think mapM with subsequent runST should work.


More information about the Haskell-Cafe mailing list