[Haskell] Re: ST/STRef vs. IO/IORef

Axel Simon A.Simon at kent.ac.uk
Thu Aug 4 04:21:40 EDT 2005


On Wed, 2005-08-03 at 12:07 -0500, Srinivas Nedunuri wrote:

> > > I was wondering what advice folks had. In particular, what are the
> > > disadvantages to doing everything in the IO monad - ie why even bother
> > > with the ST monad?
> >
> > The most obvious disadvantage is that the IO monad has no equivalent
> > of runST.
> OK, I'm missing something here. What is the big deal about runST? Can I not
> get the IO equivalent by simply running the program at the top level
> (assuming I don't have multiple threads going). Do you have a practical
> example of needing runST in several places in your program?

Having recently used the MonadReader and MonadState classes, I got the
impression that ST should actually be deprecated. It seems to me that
they are a relic from the time when there were no threads, i.e. when
everything was in a single IO monad and you couldn't run another IO
computation in independently. Nowadays, you can use one of the
MonadState monad if you want lazy computation (on top of which you can
implement state read and write accesses similar to IORefs) or IO-enabled
computation (if you use MonadState.StateT and embed an IO monad at the
core). Is this view correct? If not, could there be a comment as to what
ST is useful (rather than a reference to a full blown paper that pre-
dates the MonadState,... libraries).

Axel.




More information about the Haskell mailing list