[Haskell-beginners] State monad and destructive updates

Brent Yorgey byorgey at seas.upenn.edu
Sun Mar 18 21:02:52 CET 2012


On Sun, Mar 18, 2012 at 01:34:30PM -0400, Rohit Garg wrote:
> Hi,
> 
> As I have been trying to learn the monads a bit more, I have come to
> realize that State monad doesn't actually represent state. It just
> provides a convenient glue for threading state. Is that correct? 

Correct.

> If
> so, then for performance using state monad is as good as not using it
> at all. Is there a way to have state with destructive update?

Yes, see the ST monad.

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad-ST.html
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-STRef.html
http://hackage.haskell.org/packages/archive/array/latest/doc/html/Data-Array-ST.html

-Brent



More information about the Beginners mailing list