[Haskell-cafe] REALLY simple STRef examples

Chad Scherrer chad.scherrer at gmail.com
Thu Jul 20 13:38:43 EDT 2006


Hi,

> The short answer: use
>         runST (long expression)
> rather than
>         runST $ long expression
>
> when it comes to higher-ranked functions such as runST.

I suppose the same holds for runSTUArray, right? But this still gives
me that same error, about being less polymorphic than expected.

(+=) x y = let updateX i = do xi <- readArray x i
                              writeArray x i (xi + y!i)
           in  sequence_ . map updateX $ indices x

sumArrays [] = error "Can't apply sumArrays to an empty list"
sumArrays (x:xs) = runSTUArray result
    where
    result = do x0 <- thaw x
                mapM_ (x0 +=) xs
                x0



-- 

Chad Scherrer

"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx


More information about the Haskell-Cafe mailing list