I'm writing a small program (an extension of a Pokemon game that got posted here a while ago) where I'm trying to not use IO as much as possible. The program relies on randomness (picking a random Pokemon and move) and on writing (say things like "Pokemon X attacked you for Y damage!").
Again, I'm trying NOT to use IO, so instead I'm using Rand (Control.Monad.Random) and Writer. Now, I have a couple of functions that return Rand g a (where a can be a pokemon name or move), but I would like to "log" the name and move after they come in.
Here's a simplified version of what I'm trying to do:battle :: _ battle = do move <- getRandomMove -- returns an Rand g Move tell ["Pokemon attacked you with " ++ name move] damage <- calculateDamage -- returns an Rand g Damage tell ["And did " ++ damage] battle
Of course, this doesn't work (I'm mixing my Rands and Writers). I thought "maybe this is what Transformers are for?"). I tried using WriterT and RandT in a combination of ways, but I always go stuck, which makes me think that's not right either.
So my question are:
- Are transformers the answer to my problem?
- If so, how do you use them? (I'm failing to understands them from the tutorials I've found online)
- If not, how could I solve this problem?
Edit: Formatting Edit2: battle is recursivesubmitted by Die-Nacht
[link] [13 comments]
We have a number of openings for PhD study at the University of Birmingham, and we also have an imminent funding deadline, so please contact me (or any of us in the theory group at Birmingham) immediately if you're interested.
I personally am looking for students interested in designing the next generation of functional languages. You can find a fuller announcement here.submitted by neelk
[link] [3 comments]