<div dir="ltr">A good exercise will be to re-implement State, and then use it. Take a look here: <a href="http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State">http://en.wikibooks.org/wiki/Haskell/Understanding_monads/State</a>.<div>This link will take you to a tutorial that takes you through the implementation of State, and then uses it for random number generation.</div><div><br></div><div>Hope this helps. Enjoy !</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 April 2015 at 00:55, 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">
    I'm having some trouble using the state monad with a random number
    generator.<br>
    <br>
    I'm trying to follow the LYAH example
    (<a href="http://learnyouahaskell.com/for-a-few-monads-more" target="_blank">http://learnyouahaskell.com/for-a-few-monads-more</a>) but apparently
    the state monad API has changed, so I'm using
    Control.Monad.Trans.State.Lazy (state monad from the transformers
    package).  Side question: is using transformers a good idea?  I've
    heard some people complain about mtl's performance, others don't
    seem to care.  I'm far too new to be able to judge anything (does it
    even make sense to compare transformers vs. mtl?) but if one has
    overtaken the other I'd rather use that.<br>
    <br>
    Here's what I currently have:<br>
    import Control.Monad.Trans.State.Lazy<br>
    type GeneratorState = State StdGen<br>
    <br>
    genThree :: Int -> GeneratorState Int<br>
    genThree listMax = do --highest index in the list<br>
            let listMin = 0 :: Int --lowest index in the list<br>
            generator <- get<br>
            let (generatedMin, state) = randomR (listMin, listMax)
    generator<br>
            return generatedMin<br>
    <br>
    Although it typechecks it doesn't seem like an improvement over just
    using StdGen by itself.<br>
    <br>
    What I think I should have:<br>
    genThree :: Int -> GeneratorState Int<br>
    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>
    <b><br>
    </b>I feel like I really botched this--what am I missing?<br>
    <b><br>
    </b>
  </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><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>