[Haskell-cafe] A question about State Monad and Monad in general

Daniel Fischer daniel.is.fischer at web.de
Thu Jul 15 12:20:20 EDT 2010


On Thursday 15 July 2010 18:02:47, C K Kashyap wrote:
> Hi,
> I looked at State Monad yesterday and this question popped into my mind.
>
> >From what I gather State Monad essentially allows the use of Haskell's
> > do
>
> notation to "invisibly" pass around a state. So, does the use of Monadic
> style fetch us more than syntactic convenience?

Better refactorability.
If you're using monadic style, changing from, say,
State Thing
to
StateT Thing OtherMonad

or from
StateT Thing FirstMonad
to
StateT Thing SecondMonad

typically requires only few changes. Explicit state-passing usually 
requires more changes.

> Again, if I understand correctly, in Mutable Arrays also, is anything
> getting modified in place really?

Yes. If you write to a mutable array, you really write to the memory 
location without extra copying.

> If not, what is the real reason for
> better efficiency?



More information about the Haskell-Cafe mailing list