[Haskell] Re: ST/STRef vs. IO/IORef
Pedro Vasconcelos
pv at dcs.st-and.ac.uk
Thu Aug 4 05:31:44 EDT 2005
On Thu, 04 Aug 2005 10:09:06 +0100
Axel Simon <A.Simon at kent.ac.uk> wrote:
> Ok, granted. In particular I take your point about array accesses.
> However, I am not quite convinced that using ST has any advantages over
> using IO directly. Of course, one could claim that programmers wants to
> protect themselves from themselves by disallowing arbitrary IO. But if
> that is the only "advantage" then I'd rather go for the flexibility to
> use arbitrary IO later on without having to rewrite my whole program.
This has been mentioned before, but the point of ST vs. IO is that you
can encapsulate the update-in-place operations using runST and provide a
purely functional interface to the outside world. If the external api
doesn't need to expose the internal state and the library doesn't
require IO internally, then ST gives the best of both worlds: a pure
interface and efficiency.
I think the Data.Graph algorithms in GHC's libraries are coded in this way.
Regards,
Pedro
--
Pedro Vasconcelos, School of Computer Science, University of St Andrews
-----------------------------------------------------------------------
"In theory there is no difference between theory and practice
but in practice there is." -- Tony Davie
More information about the Haskell
mailing list