> There are few formal connections between monads and
> single-threaded state... For any state-transformer monad... there
> is a trivial operation... that will instantly destroy any hope for
> single-threadedness: getState s = (s, s)
>
> In day-to-day Haskell 1.3 programming what is the solution to this
> problem? If a program is using a C interface to create a mutable
> state, say an external database, what is the simplest way of
> encapsulating the state so that this "trivial operation" cannot be
> defined except by the original author?
A monad is an abstract data type. The implementation of an ADT is
hidden, so that the client of the ADT can't invalidate its invariants.
Its the same for state-transformer monads. The programmer can't define
this trivial operaion, because all s/he has is an ADT with an
interface like
newVar :: a -> ST (MutVar a)
readVar :: MutVar a -> ST a
writeVar :: MutVar a -> a -> ST ()
thenST :: ST a -> (a -> ST b) -> ST b
returnST :: a -> ST a
With those operations you simply can't define getState.
You might find "State in Haskell" useful (from my Web page).
Haskell 1.3 doesn't define any state-transformer monads, but both GHC
and Hugs do.
Simon