[Haskell-cafe] My first Haskell program

Ernesto Rodriguez neto at netowork.me
Mon Apr 8 15:10:39 CEST 2013


Hi John,

I am not saying it's wrong, but something you could consider trying is
using the RVars to generate the random numbers inside MonadRandom and using
lift to lift the random number generation into the state Monad and use
runStateT. The IO Monad is an instance of MonadRandom so any State +
MonadRandom computation can be run inside the IO Monad. I will write a
short piece of code to illustrate my point.

import Data.Random.Distribution.Uniform
import Control.Monad.State
import Data.RVar
...

randomState n = do
    let
       dist = uniform 1 n
    rNum <- lift $ sampleRVar dist
    put rNum

runStateT (randomState 5) 0

Using RVars, you can generate numbers from numerous distributions. You can
even have pure RVars which generate values according to a distribution once
an initialization seed is given. I hope this information serves you well.
Check out the RVar package in Haskell for more about generating random
numbers.

Best,

Ernesto Rodriguez

On Sat, Apr 6, 2013 at 6:50 PM, John Wood <j at jdtw.us> wrote:

> Hello, Cafe
>
> I'm new to Haskell and the mailing list, and am wondering if I could get
> some feedback on my first program -- a Markov text generator. The code is
> posted here:
>
> http://codereview.stackexchange.com/questions/24791/haskell-markov-text-generator
>
> Thanks,
>
> John;
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
Ernesto Rodriguez

Bachelor of Computer Science - Class of 2013
Jacobs University Bremen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130408/5e42e2b2/attachment.htm>


More information about the Haskell-Cafe mailing list