examples using built-in state monad

hello, in my program i used my own parameterised state transformer monad, which is well described in literature: newtype State s m a = ST (s -> m (a,s)) ghc and hugs contain built in implementation of state monad ST. is it the same thing? the documentation is not clear on that. if it is the same, is it faster? also, could someone please recommend any samples that use the built in ST monad? thanks konst

Mon, 26 Feb 2001 13:07:51 -0800, Konst Sushenko
newtype State s m a = ST (s -> m (a,s))
ghc and hugs contain built in implementation of state monad ST.
is it the same thing?
No. GHC's and Hugs' ST allows dynamic creation of arbitrary number of mutable variables of arbitrary types, using operations newSTRef :: a -> ST s (STRef s a) readSTRef :: STRef s a -> ST s a writeSTRef :: STRef s a -> a -> ST s () The type variable 's' is used in a very tricky way, to ensure safety when runST :: (forall s. ST s a) -> a is used to wrap the ST-monadic computation in a purely functional interface. It does not correspond to the type of data being manipulated. GHC >= 4.06 contains also a monad like yours, in module MonadState, available when -package lang option is passed to the compiler. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
participants (2)
-
Konst Sushenko
-
qrczak@knm.org.pl