lifting between two StateT monads

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

lifting between two StateT monads

Alexander Vodomerov
  Hello!

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
are welcome).

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.

   With best regards,
       Alexander.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: lifting between two StateT monads

David House
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.

--
-David House, [hidden email]
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe