[Haskell-beginners] State Monad

Thomas Jakway tjakway at nyu.edu
Fri Apr 17 23:19:36 UTC 2015


Thank you very much!

On 4/17/15 6:48 PM, Mike Meyer wrote:
>
> On Fri, Apr 17, 2015 at 2:25 PM, Thomas Jakway <tjakway at nyu.edu 
> <mailto:tjakway at nyu.edu>> wrote:
>
>     genThree listMax = do --highest index in the list
>             let listMin = 0 :: Int --lowest index in the list
>             generatedMin <- state randomR (listMin, listMax)
>             return generatedMin
>
>
> What you're missing is a $:
>
> The only chagne to our genThree functions is making it "state $" 
> instead of "state".
>
>
> #!/usr/bin/env runhaskell
>
> import System.Random
> import Control.Monad.State
>
> genThree listMax = do --highest index in the list
>         let listMin = 0 :: Int --lowest index in the list
>         generatedMin <- state $ randomR (listMin, listMax)
>         return generatedMin
>
> main = do
>   gen <- newStdGen
>   print $ evalState (genThree 10) gen
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150417/ff279697/attachment-0001.html>


More information about the Beginners mailing list