State Transformer

Jan-Willem Maessen [email protected]
Fri, 11 Jan 2002 12:39:54 -0500

Theodore Norvell <[email protected]> asks:
> Jorge's question raised a question in my mind.  The IOExts
> module has many of the same features as the ST module, why
> are there two ways to do the same thing?  Is the ST module
> only there for legacy purposes?

The ST monad provides safer encapsulation of mutable references.  We
can prove that references which escape a particular instance of ST are
never side effected.  See the paper "Lazy Functional State Threads":

This allows us to construct functions which are certain to present a
functional face to the world, but use mutation internally.  In this
respect, ST is actually "better" than IO, albeit less well-supported.

-Jan-Willem Maessen

[Note that the above paper presents the version of ST contained in the
LazyST library these days (if my memory serves me right).  The
arguments about encapsulation apply in either case.]