[Haskell-cafe] REALLY simple STRef examples

Chad Scherrer chad.scherrer at gmail.com
Thu Jul 20 16:26:58 EDT 2006


Ok, I see now why the return is necessary. For now I'll switch to
boxed arrays until I get the rest of this down better.

But why should this...

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

work differently than this...

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

Are the types of (result x) and result' not exactly the same?


-- 

Chad Scherrer

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


More information about the Haskell-Cafe mailing list