<div dir="ltr">Ok, now the analysis. Without the $, you get this error message (ghci 7.8.3):<div><br></div><div><div>    Couldn't match type ‘g0 -> (a0, g0)’ with ‘(a, (a0, a0))’</div><div>    Expected type: (a0, a0) -> (a, (a0, a0))</div><div>      Actual type: (a0, a0) -> g0 -> (a0, g0)</div><div>    Relevant bindings include</div><div>      genThree :: t -> a (bound at /tmp/test.hs:6:1)</div><div>    Probable cause: ‘randomR’ is applied to too few arguments</div><div>    In the first argument of ‘state’, namely ‘randomR’</div><div>    In a stmt of a 'do' block: state randomR (listMin, listMax)</div></div><div><br></div><div>The key line is "Probable cause: 'randomR' is applied to too few arguments". Since it takes and apparently has one argument, the most likely cause is that the expression isn't parsed the way you expect.. So make the parse explicit, which would be "state (randomR (listMin, listMax))".  Using the $ operator does the same thing, and reads a bit cleaner once you get used to it.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 17, 2015 at 6:19 PM, Thomas Jakway <span dir="ltr"><<a href="mailto:tjakway@nyu.edu" target="_blank">tjakway@nyu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Thank you very much!<br>
    <br>
    <div>On 4/17/15 6:48 PM, Mike Meyer wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Fri, Apr 17, 2015 at 2:25 PM,
            Thomas Jakway <span dir="ltr"><<a href="mailto:tjakway@nyu.edu" target="_blank">tjakway@nyu.edu</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000">genThree listMax =
                do --highest index in the list<br>
                        let listMin = 0 :: Int --lowest index in the
                list<br>
                        generatedMin <- state randomR (listMin,
                listMax)<br>
                        return generatedMin<br>
              </div>
            </blockquote>
          </div>
          <br>
          What you're missing is a $:</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">The only chagne to our genThree
          functions is making it "state $" instead of "state". </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">#!/usr/bin/env runhaskell</div>
        <div class="gmail_extra">
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">import System.Random</div>
          <div class="gmail_extra">import Control.Monad.State</div>
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">genThree listMax = do --highest index
            in the list<br>
          </div>
          <div class="gmail_extra">        let listMin = 0 :: Int
            --lowest index in the list</div>
          <div class="gmail_extra">        generatedMin <- state $
            randomR (listMin, listMax)</div>
          <div class="gmail_extra">        return generatedMin</div>
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">main = do<br>
          </div>
          <div class="gmail_extra">  gen <- newStdGen</div>
          <div class="gmail_extra">  print $ evalState (genThree 10) gen</div>
          <div><br>
          </div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>_______________________________________________
Beginners mailing list
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
    </blockquote>
    <br>
  </div>

<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>