RE: Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Simon Peyton-Jones
| ps: you successfully going through all the standard Haskell troubles in | this area :) seems that making FAQ about using ST monad will be a | good idea :) Indeed. If someone would like to start one, a good place for it would be GHC's collaborative-documentation Wiki http://haskell.org/

Re: Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Udo Stenzel
Chad Scherrer wrote: > 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 tha

Re: Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Chad Scherrer
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