<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Thanks for the tip, Ozgur. It worked for me. Is this what you had in mind, Ryan?<br><br>Michael<br><br>==============<br><br>import Control.Monad.State.Lazy<br>import Control.Monad<br>import System.Random<br><br>type GeneratorState = State StdGen<br>data Craps a = Roll a | Win a | Lose a deriving (Show)<br><br>genRandomR :: Random a => (a,a) -> GeneratorState a<br>genRandomR = state . randomR<br><br>rollDie :: GeneratorState Int<br>rollDie = genRandomR (1,6)<br><br>roll2Dice :: GeneratorState Int<br>roll2Dice = liftM2 (+) rollDie rollDie<br><br>f :: Craps [Int] -> GeneratorState (Craps [Int])<br>f (Roll []) = do g0 <- get<br> let (throw1,g1) = runState roll2Dice
g0<br> put g1<br> case throw1 of<br> 2 -> return (Lose [throw1])<br> 3 -> return (Lose [throw1])<br> 7 -> return (Win [throw1])<br> 11 -> return (Win [throw1])<br> _ -> do g1 <-
get<br> let (throw2,g2) = runState roll2Dice g1<br> put g2<br> if throw2 == throw1<br> then do return (Win [throw1,throw2])<br>
else<br> if throw2 == 7<br> then do return (Lose [throw1,throw2])<br> else do f (Roll [throw1,throw2])<br>f (Roll z@(throw1:throws)) = do g0 <- get<br> let (throw,g1) = runState roll2Dice
g0<br> put g1<br> if throw == throw1<br> then do return (Win (z ++ [throw]))<br>
else<br> if throw == 7<br> then do return (Lose (z ++ [throw]))<br> else do f (Roll (z ++ [throw]))<br><br><br><br>--- On <b>Wed, 12/22/10, Ozgur Akgun <i><ozgurakgun@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From:
Ozgur Akgun <ozgurakgun@gmail.com><br>Subject: Re: [Haskell-cafe] Why is Haskell flagging this?<br>To: "Ryan Ingram" <ryani.spam@gmail.com><br>Cc: haskell-cafe@haskell.org, "Daniel Fischer" <daniel.is.fischer@googlemail.com><br>Date: Wednesday, December 22, 2010, 7:37 PM<br><br><div id="yiv758049062">see also: <a rel="nofollow" target="_blank" href="http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Lazy.html#v:state">http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Lazy.html#v:state</a><br>
<br><div class="yiv758049062gmail_quote">On 22 December 2010 20:02, Ryan Ingram <span dir="ltr"><<a rel="nofollow" ymailto="mailto:ryani.spam@gmail.com" target="_blank" href="/mc/compose?to=ryani.spam@gmail.com">ryani.spam@gmail.com</a>></span> wrote:<br><blockquote class="yiv758049062gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>Interesting. In that case,<br>
<br>
state f = StateT $ \s -> Identity (f s)<br>
<br>
allows "state" to replace "State" in that code.</div></blockquote></div><br clear="all">Ozgur
</div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>Haskell-Cafe mailing list<br><a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></div></blockquote></td></tr></table><br>