[Haskell-cafe] Very simple parser

Ilya Tsindlekht eilya497 at 013.net
Wed Jul 4 15:44:42 EDT 2007

On Thu, Jul 05, 2007 at 12:58:06AM +1000, Alexis Hazell wrote:
> On Tuesday 03 July 2007 09:51, Arie Peterson wrote:
> > No, there is a 'State s' monad provided (for arbitrary state type 's'),
> > which implements the 'get' and 'put' methods. In other words, 'State s' is
> > an instance of the 'MonadState s' class. This terminology can be really
> > confusing at first.
> >
> > For now, you may forget about the MonadState class. Simply use 'get' &
> > friends and everything will work fine.
> This may be a stupid question, but i don't understand how (indeed, if) one can 
> maintain multiple states using the State monad, since 'get' etc. don't seem 
> to require that one specify which particular copy of a State monad one wishes 
> to 'get' from, 'put' to etc.? Does one have to use (say) a tuple or a list to 
> contain all the states, and when one wishes to change only one of those 
> states, pass that entire tuple or list to 'put' with one element changed and 
> the rest unchanged?
> Alexis.
A value of type 'State t' contains an incapsulated function can be
de-encapsulated using runState and when evaluated, performs the actual
computation. This function maintains state internally, so for each
invocation of this function (such functions from other values of type
'State t') state is preserved separately. 

Hope this clarifies your confusion.

More information about the Haskell-Cafe mailing list