<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    That's a good idea, though not understanding the state monad is
    still pretty frustrating.<br>
    <br>
    <div class="moz-cite-prefix">On 2/12/16 6:38 AM, Nikita Kartashov
      wrote:<br>
    </div>
    <blockquote
      cite="mid:11EEE5C9-9376-4D75-8A1A-8B7D24C83F62@gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <div>Hi!</div>
      <div><br>
      </div>
      <div>Take a look at MonadRandom [1]. It is basically what you want
        without getting generator explicitly.</div>
      <div><br>
      </div>
      <div>[1] <a moz-do-not-send="true"
          href="https://hackage.haskell.org/package/MonadRandom">https://hackage.haskell.org/package/MonadRandom</a></div>
      <br>
      <div>
        <div>With regards,</div>
        <div>Nikita Kartashov</div>
        <div><br>
        </div>
        <br class="Apple-interchange-newline">
      </div>
      <br>
      <div>
        <div>On 12 Feb 2016, at 04:14, Thomas Jakway <<a
            moz-do-not-send="true" href="mailto:tjakway@nyu.edu"><a class="moz-txt-link-abbreviated" href="mailto:tjakway@nyu.edu">tjakway@nyu.edu</a></a>>
          wrote:</div>
        <br class="Apple-interchange-newline">
        <blockquote type="cite">I'm having a bad time using the State
          monad to generate random numbers without carrying around a lot
          of StdGens manually.<br>
          I have this snippet in the IO monad:<br>
          <br>
             ... IO stuff ...<br>
             gen <- getStdGen<br>
             let (numPlayers, numMatches) = (evalState genRandVariables
          gen) :: (Integer, Integer)<br>
             ... More IO stuff ...<br>
          <br>
             where maxRandPlayers = 10 :: Integer<br>
                   minRandMatches = 10 :: Integer<br>
                   maxRandMatches = 100 :: Integer<br>
                   genRandVariables = (do<br>
                         np <- randomR (1, maxRandPlayers) --minimum
          1 other player<br>
                         nm <- randomR (minRandMatches,
          maxRandMatches)<br>
                         return (np, nm)) :: State StdGen (Integer,
          Integer)<br>
          <br>
          <br>
          I get this error message:<br>
test/Jakway/Blackjack/Tests/IntegrationTests/MatchTests.hs:53:23:<br>
             Couldn't match expected type ‘StateT<br>
                                             StdGen
          Data.Functor.Identity.Identity Integer’<br>
                         with actual type ‘g0 -> (Integer, g0)’<br>
             Probable cause: ‘randomR’ is applied to too few arguments<br>
             In a stmt of a 'do' block: np <- randomR (1,
          maxRandPlayers)<br>
             In the expression:<br>
                 (do { np <- randomR (1, maxRandPlayers);<br>
                       nm <- randomR (minRandMatches,
          maxRandMatches);<br>
                       return (np, nm) }) ::<br>
                   State StdGen (Integer, Integer)<br>
          <br>
test/Jakway/Blackjack/Tests/IntegrationTests/MatchTests.hs:54:23:<br>
             Couldn't match expected type ‘StateT<br>
                                             StdGen
          Data.Functor.Identity.Identity Integer’<br>
                         with actual type ‘g1 -> (Integer, g1)’<br>
             Probable cause: ‘randomR’ is applied to too few arguments<br>
             In a stmt of a 'do' block:<br>
               nm <- randomR (minRandMatches, maxRandMatches)<br>
             In the expression:<br>
                 (do { np <- randomR (1, maxRandPlayers);<br>
                       nm <- randomR (minRandMatches,
          maxRandMatches);<br>
                       return (np, nm) }) ::<br>
                   State StdGen (Integer, Integer)<br>
          <br>
          What's really baffling to me is I feel like this is how it
          *should* look--that the whole point of the state monad is to
          *not* have to explicitly pass the StdGen to randomR.  What am
          I doing wrong?<br>
          _______________________________________________<br>
          Beginners mailing list<br>
          <a moz-do-not-send="true" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
          <a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
        </blockquote>
      </div>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>