[Haskell-beginners] State monad question
Jordan Cooper
nefigah at gmail.com
Wed Jun 23 19:10:42 EDT 2010
Alright, I'll give this a shot. I've never used monad transformers
before, so it should be interesting :)
On 6/23/10, Daniel Fischer <daniel.is.fischer at web.de> wrote:
> On Wednesday 23 June 2010 23:48:42, Jordan Cooper wrote:
>>
>> 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 :)
>
> Maybe a Monad transformer would be helpful, something along the lines of
>
> StateT Player (State Card) foo
>
> then you can work in the inner Monad (State Card) via lift.
>
> fooBar = do
> cardResult <- lift cardAction
> playerResult <- playerAction cardResult
> return (cardResult, playerResult)
>
More information about the Beginners
mailing list