
Omitting the typeclass bit, I'm trying to write something like (s1 -> s2) -> StateT s1 m () -> StateT s2 m a -> StateT s1 m a That is, it sequences two StateT computations, providing a way to translate from the first's state to the second to keep the chain going. I can easily write something for when s1 and s2 are the same, and my understanding of much of Control.Monad.* remains tenuous at best, but if it's easy for anyone to provide me with some tips, then I thought I should mention that it'd certainly be helpful. And Happy New Year, everyone! -- Mark

Mark, I'm no expert, but does it help to start from withStateT?
withStateT :: (s -> s) -> StateT s m a -> StateT s m a withStateT f m = StateT $ runStateT m . f
There are some notes about computations and lifting state transformers in Modular Denotational Semantics for Compiler Construction Sheng Liang, Paul Hudak http://citeseer.nj.nec.com/liang96modular.html Monad Transformers and Modular Interpreters Sheng Liang, Paul Hudak, Mark Jones http://citeseer.nj.nec.com/liang95monad.html Don't mind me: I just couldn't control the vestiges of librarianship lurking in my dark, lost soul... Dobrego Nowego Roku! Chris Milton (no, not MLton:-) --- Mark Carroll wrote:
Omitting the typeclass bit, I'm trying to write something like (s1 -> s2) -> StateT s1 m () -> StateT s2 m a -> StateT s1 m a
That is, it sequences two StateT computations, providing a way to translate from the first's state to the second to keep the chain going.
I can easily write something for when s1 and s2 are the same, and my understanding of much of Control.Monad.* remains tenuous at best, but if it's easy for anyone to provide me with some tips, then I thought I should mention that it'd certainly be helpful.
And Happy New Year, everyone!
-- Mark _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Mark Carroll wrote in article
Omitting the typeclass bit, I'm trying to write something like (s1 -> s2) -> StateT s1 m () -> StateT s2 m a -> StateT s1 m a
That is, it sequences two StateT computations, providing a way to translate from the first's state to the second to keep the chain going.
Don't you need a (s2 -> s1) function as well, to translate the final state back into StateT s1? -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig GW Bush: And when leaders make the wise and responsible choice, when they renounce terror and weapons of mass destruction, as Col. Ghadafi has now done, they serve the interest of their own people and they add to the security of all nations. http://www.tmealf.com/survey_form.htm

On Wed, 31 Dec 2003, Ken Shan wrote:
Don't you need a (s2 -> s1) function as well, to translate the final state back into StateT s1?
Yes, you're right: the thing actually running the stateful computation presumably expects to start it with a state of type s1 and to be able to extract from it a state of type s1 when it's done. -- Mark
participants (3)
-
Christopher Milton
-
Ken Shan
-
Mark Carroll