I've just started learning Haskell and have a simple question regarding
monads. Please, don't blame me if it is too obvious (any RTFM links
Suppose, we have two data types, X and Y. X represent local state, Y --
global one. In some sense, X is contained in Y. For example, Y maybe (X,
Z) or [X] or Map Int X. Let's take that (as it is in my case)
Y = Map Int X
I have function that make some transormation of local state (X) and
having some other side effects.
f :: StateT X m a
where m is another monad, something like WriterT Log IO.
Now I want to convert it into function transorming global state, more
specifically it's n-th part. So, I want to combine n :: Int and f into
g :: StateT Y m a
where (Y ! n) is transormed via f, and other parts of Y are not touched.
How can this be done?
I've looked through StateT documentation and tutorial, but had not found
any function from StateT X to StateT Y where Y is not the same as X.
Apologies to Alexander for the multiple copies, I forgot to hit 'Reply
to all' again.
On 01/07/06, Alexander Vodomerov <[hidden email]> wrote:
> I've looked through StateT documentation and tutorial, but had not found
> any function from StateT X to StateT Y where Y is not the same as X.
Try runState. You'd need to grab the state in your g computation, then
runState f with the nth part of Y.