[Haskell-beginners] State monad question

Jordan Cooper nefigah at gmail.com
Wed Jun 23 17:48:42 EDT 2010

On 6/23/10, Drew Haven <drew.haven at gmail.com> wrote:
> I doubt it's an issue of being too stupid.  If you come from more
> traditional languages, then Haskell requires that to rewire your brain
> 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.

You're probably right, but I can't help but have some doubts :)

> 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
> need to be monadic.

Well, two things that I guess are important to mention:

In my program, it's not Foo and Bar, but Cards and Players. Any player
can potentially act on any card, even if it's not their own, thus I
felt they probably shouldn't be part of the same state (though perhaps
I am wrong in this).

Secondly, as to why I wanted to use a monad here, importantFunction
(which is called playerTurn in the real program) would contain a
series of functions that would modify Cards and Players, not just one
each as in my initial example. Thus it seems like I'd have to end up
with let foo... let foo'... etc. which, from my reading in RWH, seems
to be an acceptable use for a State monad.

Thanks for your answer, and to Matthew for the encouragement :)

More information about the Beginners mailing list