Yitzchak Gale wrote:
> 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

Are there any useful functions of this type?  I guess, your intention is
that this "transformer" makes no other use of the ST monad than reading
or writing a single variable.  It seems, every such function better had
a purely functional interface anyway, even if it makes use of runST
internally.

 
> stToState :: MonadState st m => (STRef s st -> ST s a) -> m a
> 
> The type signatures above do ensure (as far as I can see)
> that the opacity of the ST state thread is not violated.

I doubt that.  The "transformer" you pass in could have captured
references from a different state thread, which is exactly the problem
the rank-2 type should prevent.  I guess, the type signature you want is

stToState :: MonadState st m => (forall s . STRef s st -> ST s a) -> m a

which should actually work with runST and which would also be a bit
pointless (see above).  At least if I got rank-2 types correctly, which
isn't guaranteed.


> Any ideas? A better approach?

Uhm... use MonadState in the first place?  The converse is comparatively
easily accomplished:

stateToST :: STRef s st -> State st a -> ST s a
stateToST ref action = do (a, st') <- readSTRef ref >>= runState action
                          writeSTRef ref st'
                          return a
 

-Udo
-- 
"Human legalese is the schema language of our society."
        -- Tim Berners-Lee in http://w3.org/DesignIssues/Evolution

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to