[Haskell-cafe] using mutable data structures in pure functions

Ben Gamari bgamari.foss at gmail.com
Mon Mar 12 04:52:35 CET 2012

I'm sure others will want to chime in here, but I'll offer my two cents.

On Sun, 11 Mar 2012 22:38:56 -0500, E R <pc88mxer at gmail.com> wrote:
> So, again, what is the Haskell philosophy towards using mutable data
> structures in pure functions? Is it:
> 1. leave it to the compiler to find these kinds of opportunities
> 2. just use the immutable data structures - after all they are just as
> good (at least asymptotically)
> 3. you don't want to use mutable data structures because of _____
> 4. it does happen, and some examples are ______
You will find that a surprising amount of the time this will be
sufficient. After all, programmer time is frequently more expensive than
processor time.

That being said, there are some cases where you really do want to be
able to utilize a mutable data structure inside of an otherwise pure
algorithm. This is precisely the use of the ST monad. ST serves to allow
the use of mutable state inside of a function while hiding the fact from
the outside world.


- Ben

More information about the Haskell-Cafe mailing list