Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Random Numbers with the State Monad (Thomas Jakway)


----------------------------------------------------------------------

Message: 1
Date: Sat, 13 Feb 2016 10:37:50 -0500
From: Thomas Jakway <tjak...@nyu.edu>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Random Numbers with the State Monad
Message-ID: <56bf4dce.1010...@nyu.edu>
Content-Type: text/plain; charset=utf-8; format=flowed

Thanks!  That makes sense

On 2/12/16 8:26 AM, Marcin Mrotek wrote:
> Hello,
>
> You have this type error:
>
> Couldn't match expected type ?StateT
>                                      StdGen
> Data.Functor.Identity.Identity Integer?
>                  with actual type ?g1 -> (Integer, g1)?
>
> It's because you're trying to use a `(s -> (a,s))` function
> "unwrapped" where GHC expects it "wrapped" in a StateT.
> The type of `state` from Control.Monad.State (mtl package) is:
>
> state :: (s -> (a, s)) -> m a
>
> so it could solve your mismatch, turning `g1 -> (Integer, g1)` into
> `StateT StdGen Identity Integer`, like:
>
> np <- state (randomR (1, maxRandPlayers))
>
> Alternatively, if you don't want to use mtl, you can use `StateT`s
> constructor directly. It's type is:
>
> StateT :: (s -> m (a, s)) -> StateT s m a
>
> so you'd have to compose `randomR` with `return` (or `pure`) first:
>
> np <- StateT (return . randomR (1, maxRandPlayers))
>
> Best regards,
> Marcin Mrotek
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 92, Issue 16
*****************************************

Reply via email to