[Haskell-cafe] lifting between two StateT monads

Alexander Vodomerov alex at sectorb.msk.ru
Sat Jul 1 06:21:57 EDT 2006


  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.


More information about the Haskell-Cafe mailing list