Drew Haven drew.haven at gmail.com
Wed Jun 23 17:32:10 EDT 2010

I doubt it's an issue of being too stupid.  If you come from more
to think in Haskell.  It's very different.  It appears hard because
there is a lot of work to re-learning things you thought you knew.

As for combining two state monads, is there a reason you cannot
combine them into one large state?

It looks what you are doing is:

importantFunction initialFoo initialBar =
let foo = execState modifiesFoo initialFoo
in (foo, execState (modifiesBar foo) initialBar)

Which would have the type signature you are expecting and wouldn't

Drew Haven
drew.haven at gmail.com

On Wed, Jun 23, 2010 at 2:10 PM, Jordan Cooper <nefigah at gmail.com> wrote:
> I have two pieces of state I'm managing:
> type FooState = State Foo Foo
> type BarState = State Bar Bar
>
> There is a bit of interplay between them, and I want a function that
> does something like:
> importantFunction :: Foo -> Bar -> (Foo, Bar)
>
> The problem is, >>= only works when I'm chaining all of the same type
> of state. So I can't do:
> modifiesFoo >>= \foo ->
> modifiesBar foo >>= \bar ->
> return (foo, bar)
>
> So how do I get the results of both modifications back? I hope that
> makes sense. Programming in Haskell is proving to be very difficult; I
> once again fear I'm too stupid.
> _______________________________________________
> Beginners mailing list