Re: [Haskell-cafe] random question

2009-10-08 Thread Nicolas Pouillard
Excerpts from Bryan O'Sullivan's message of Wed Oct 07 23:25:10 +0200 2009: On Wed, Oct 7, 2009 at 1:59 PM, Michael Mossey m...@alumni.caltech.eduwrote: My thread about randomness got hijacked so I need to restate my remaining question here. Is it acceptable to write pure routines that use

[Haskell-cafe] random question

2009-10-07 Thread Michael Mossey
My thread about randomness got hijacked so I need to restate my remaining question here. Is it acceptable to write pure routines that use but do not return generators, and then call several of them from an IO monad with a generator obtained by several calls to newStdGen? shuffle :: RandomGen

Re: [Haskell-cafe] random question

2009-10-07 Thread Luke Palmer
On Wed, Oct 7, 2009 at 2:59 PM, Michael Mossey m...@alumni.caltech.edu wrote: My thread about randomness got hijacked so I need to restate my remaining question here. Is it acceptable to write pure routines that use but do not return generators, and then call several of them from an IO monad

Re: [Haskell-cafe] random question

2009-10-07 Thread Bryan O'Sullivan
On Wed, Oct 7, 2009 at 1:59 PM, Michael Mossey m...@alumni.caltech.eduwrote: My thread about randomness got hijacked so I need to restate my remaining question here. Is it acceptable to write pure routines that use but do not return generators, and then call several of them from an IO monad

Re: [Haskell-cafe] random question

2009-10-07 Thread Michael Mossey
Luke Palmer wrote: On Wed, Oct 7, 2009 at 2:59 PM, Michael Mossey m...@alumni.caltech.edu wrote: My thread about randomness got hijacked so I need to restate my remaining question here. Is it acceptable to write pure routines that use but do not return generators, and then call several of

Re: [Haskell-cafe] random question

2009-10-07 Thread Daniel Fischer
Am Mittwoch 07 Oktober 2009 23:28:59 schrieb Michael Mossey: Luke Palmer wrote: On Wed, Oct 7, 2009 at 2:59 PM, Michael Mossey m...@alumni.caltech.edu wrote: My thread about randomness got hijacked so I need to restate my remaining question here. Is it acceptable to write pure routines

Re: [Haskell-cafe] random question

2009-10-07 Thread Ryan Ingram
On Wed, Oct 7, 2009 at 2:28 PM, Michael Mossey m...@alumni.caltech.eduwrote: I don't quite follow your response. I want a program that initializes the generator from the global generator because I want different behavior every time I run it. So it will need IO. That's what I was trying to

Re: [Haskell-cafe] Random question

2008-09-25 Thread Ariel J. Birnbaum
And the one liner: (rand 1 10) = return . (\v - take v [1..10]) What about: take $ rand 1 10 * pure [1..10] (more readable IMHO). One could even define: f % x = f * pure x and have take $ rand 1 10 % [1..10] Also, why not using getRandomR(1,10) instead? take $ getRandomR

Re: [Haskell-cafe] Random question

2008-09-25 Thread wren ng thornton
Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking. Yet

[Haskell-cafe] Random question

2008-09-24 Thread Iain Barnett
Hi, I have a function, that produces a random number between two given numbers rand :: Int - Int - IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty type-error

Re: [Haskell-cafe] Random question

2008-09-24 Thread Lev Walkin
Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int - Int - IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 ) [1..10] and see [1,2,3,4] ... or anything but nasty

Re: [Haskell-cafe] Random question

2008-09-24 Thread Lev Walkin
forgot return, of course: myTake :: IO [Int] myTake = do n - rand 1 10 return $ take n [1..10] Lev Walkin wrote: Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int - Int - IO Int rand low high = getStdRandom (randomR

Re: [Haskell-cafe] Random question

2008-09-24 Thread Evan Laforge
On Wed, Sep 24, 2008 at 2:03 PM, Iain Barnett [EMAIL PROTECTED] wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int - Int - IO Int rand low high = getStdRandom (randomR (low,high)) (Naively) I'd like to write something like take (rand 1 10 )

Re: [Haskell-cafe] Random question

2008-09-24 Thread John Van Enk
And the one liner: (rand 1 10) = return . (\v - take v [1..10]) On Wed, Sep 24, 2008 at 5:10 PM, Lev Walkin [EMAIL PROTECTED] wrote: forgot return, of course: myTake :: IO [Int] myTake = do n - rand 1 10 return $ take n [1..10] Lev Walkin wrote: Iain Barnett wrote: Hi,

Re: [Haskell-cafe] Random question

2008-09-24 Thread Iain Barnett
Your forgetfulness boosted my ego for a few seconds - I wasn't the only one! :) Thanks very much, that's a big help. Iain On 24 Sep 2008, at 10:10 pm, Lev Walkin wrote: forgot return, of course: myTake :: IO [Int] myTake = do n - rand 1 10 return $ take n [1..10] Lev Walkin

Re: [Haskell-cafe] Random question

2008-09-24 Thread Henning Thielemann
On Wed, 24 Sep 2008, Iain Barnett wrote: Hi, I have a function, that produces a random number between two given numbers rand :: Int - Int - IO Int rand low high = getStdRandom (randomR (low,high)) If you only need arbitrary numbers, not really random ones, you should stay away from IO:

Re: [Haskell-cafe] Random question

2008-09-24 Thread Iain Barnett
On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking. On 24 Sep 2008, at 10:13 pm,

Re: [Haskell-cafe] Random question

2008-09-24 Thread Henning Thielemann
On Wed, 24 Sep 2008, Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll

Re: [Haskell-cafe] Random question

2008-09-24 Thread Jonathan Cast
On Wed, 2008-09-24 at 22:44 +0100, Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well

Re: [Haskell-cafe] Random question

2008-09-24 Thread Brandon S. Allbery KF8NH
On 2008 Sep 24, at 17:44, Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but