Hey! I just wanted to let you know I made it. I just changed the newtype declaration to:<div>&gt; newtype Game r = Game { execGame :: Int -&gt; (Maybe r,Int) }</div><div>and from there everything went just fine.</div><div>

<br></div><div>Thank you for your responses,</div><div><br></div><div>Hector Guilarte<br><br><div class="gmail_quote">On Wed, Jul 7, 2010 at 9:24 PM, Hector Guilarte <span dir="ltr">&lt;<a href="mailto:hectorg87@gmail.com">hectorg87@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br><div class="gmail_quote"><div class="im">On Wed, Jul 7, 2010 at 8:48 PM, John Meacham <span dir="ltr">&lt;<a href="mailto:john@repetae.net" target="_blank">john@repetae.net</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Are you sure you are interpreting what &#39;die&#39; should do properly? Your<br>
code makes sense if die should decrement your life counter and continue<br>
along, however if &#39;die&#39; is meant to end your whole game, then there is<br>
another implementation that does type check.<br>
<br>
        John<br></blockquote><div> </div></div><div>You&#39;re absolutely right, I sen&#39;t the wrong code, here&#39;s the &quot;correct&quot; one and a little bit more explanation about what checkpoint does.  </div><div>

<br>
</div><div><div>The result of die makes sense for the checkPoint function since there are three cases for it:<br>1) The player died and has no remaining lifes. The game can&#39;t continue, I just return Noting in the die function and in checkpoint make the corresponding case.</div>


<div>2) The player died and has remaining lifes. The game can be retried with a life subtracted. I would need to tell checkpoint that I died and I want to retry, that&#39;s where I think the result is important, because of the next case.</div>


</div><div>3) The player didn&#39;t died, it finished the particular game and checkpoint m equals m. Here I would need to see if the result of the game was different from the result from die, and continue.</div><div><br>

</div>
<div><div class="im"><div>instance GameMonad Game where</div><div>  extraLife    = Game $ \l -&gt; Just ((),l+1)</div><div>  getLives     = Game $ \l -&gt; Just (l,l)</div><div>  die          = do</div><div>    n &lt;- getLives</div>

</div><div>
    if n &lt;= 0 then Game $ \_ -&gt; Nothing</div><div>      else Game $ \_ -&gt; Just (&quot;player died&quot;,n-1)</div><div>  checkPoint a = do</div><div>    n &lt;- getLives</div><div>    case execGame a n of</div><div>


      Nothing -&gt; Game $ \_ -&gt; Nothing</div><div>      Just c  -&gt; gameOn $ fst c</div><div>        where gameOn &quot;player died&quot; = a &gt;&gt;= \_ -&gt; (checkPoint a)</div><div>              gameOn _             = a</div>


</div><div> </div><div>Obviously this fails to compile because I&#39;m returning a String and it doesn&#39;t match with a either, but the idea of what I think I need to do is right there.</div><div><br></div><div><span style="font-size:13px;border-collapse:collapse"><font face="arial, helvetica, sans-serif">Ivan Miljenovic told</font></span> me to use error, and actually I though something like that. in STM retry combined with atomically does something similar as what I need checkpoint and die to do, and they use exceptions to accomplish it. I really think that&#39;s the solution I want, but then I have another question, when I &#39;throw&#39; the exception in die and &#39;catch&#39; it in checkpoint to call it again, is the number of lives gonna be lives - 1?</div>


<div><br></div><div>Thanks for answering so quickly,</div><div><br></div><div>Hector Guilarte</div><div><br></div><div>Pd: Here&#39;s an example run of how my homework should work after is finished</div><div><br></div><div>


<div>printLives :: ( GameMonad m , MonadIO m ) = &gt; String -&gt; m ()</div><div>printLives = do</div><div>  n &lt;- getLives</div><div>  liftIO $ putStrLn $ s ++ &quot; &quot; ++ show n</div><div>test1 :: ( GameMonad m , MonadIO m ) = &gt; m ()</div>


<div>test1 = checkPoint $ do</div><div>  printLives &quot; Vidas : &quot;</div><div>  die</div><div>  liftIO $ putStrLn &quot; Ganamos ! &quot;</div></div><div><br></div><div><div>lastChance :: GameMonad m = &gt; m ()</div>


<div>lastChance = do</div><div>  n &lt;- getLives</div><div>  if n == 1 then return ()</div><div>             else die</div><div>test2 :: ( GameMonad m , MonadIO m ) = &gt; m String</div><div>test2 = checkPoint $ do</div>


<div>  printLives &quot; Inicio &quot;</div><div>  n &lt;- getLives</div><div>  if n == 1</div><div>    then do</div><div>      liftIO $ putStrLn &quot; Final &quot;</div><div>      return &quot; Victoria ! &quot;</div><div>


    else do</div><div>      checkPoint $ do</div><div>        printLives &quot; Checkpoint anidado &quot;</div><div>        lastChance</div><div>      extraLife</div><div>      printLives &quot; Vida extra ! &quot;</div>

<div>
      die</div></div><div><br></div><div>AND THE OUTPUT TO SOME CALLS</div><div><br></div><div><div>ghci &gt; runGameT test1 3</div><div>Vidas : 3</div><div>Vidas : 2</div><div>Vidas : 1</div><div>Nothing</div><div>ghci &gt; runGameT test2 3</div>


<div>Inicio 3</div><div>Checkpoint anidado 3</div><div>Checkpoint anidado 2</div><div>Checkpoint anidado 1</div><div>Vida extra ! 2</div><div>Inicio 1</div><div>Finish</div><div>Just ( &quot; Victoria ! &quot; ,1)</div></div>


<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font color="#888888">
--<div class="im"><br>
John Meacham - ⑆<a href="http://repetae.net" target="_blank">repetae.net</a>⑆john⑈ - <a href="http://notanumber.net/" target="_blank">http://notanumber.net/</a><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">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></font></blockquote></div><br>
</blockquote></div><br></div>