
Horribly enough this one seems to work...
mapOnBofA :: SB a -> SA a mapOnBofA mf = get >>= \st@(A {b=temp}) -> let (ans,temp2) = runState mf temp in put (st { b=temp2}) >> return ans
There is nothing horrible about that. You just run a new isolated
computation in the State Monad for B and use its results. More or less
see same solution as Dupont's.
@Dupont:
telling from your possible use case and your last post with your "MAP"-
Problem, these two are very similar. You have a monad and inside your
monad you temporarily want to run some computation in another Monad. I
think Monad-Transformers are maybe the better option for you
(especially your interpreter-Problem was a good use case for StateT/
ErrorT instead of State and some Either inside it...).
On 29 Okt., 17:35, Stephen Tetley
2010/10/29 Dupont Corentin
: Also, I can't manage to write the more generic function SB x -> SA x.
However, I'd have to question why you want both SA and SB as state functional types. Having inner runState's is sometimes good practice (its an instance of the Local Effect pattern identified by Ralf Laemmel and Joost Visser), but if you have it "commonly" I'd suspect you design is somehow contrived and could be simplified. _______________________________________________ Haskell-Cafe mailing list Haskell-C...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe