[Haskell-cafe] Composing functions with runST
gale at sefer.org
Mon Jan 1 13:43:43 EST 2007
Simon Peyton-Jones wrote:
> There is nothing wrong with the program you are writing,
> but it's hard to design a type inference algorithm that can
> figure out what you are doing.
Thank you for your response. What I was actually trying to
do was this:
It seems to me that a natural notion of a state transformer
in the ST monad is the type:
STRef s st -> ST s a
That is in some sense intermediate between pure monadic
state transformers on the one hand, and doing state completely
within the ST or IO monad with STRefs or IORefs.
The idea is that you could then write converter functions
stToState :: MonadState st m => (STRef s st -> ST s a) -> m a
That would make it very convenient, for example, to
use arrays inside a pure state monad.
The type signatures above do ensure (as far as I can see)
that the opacity of the ST state thread is not violated. But
unfortunately, the protective shield in runST created by the
higher-rank polymorphism is too thick.
Any ideas? A better approach?
More information about the Haskell-Cafe