No leak in sight.
-- Lennart
import Random
import Array
randomElts :: RandomGen g = g - [a] - [a]
randomElts _ [] = []
randomElts g xs = map (a!) rs
where a = listArray (1, n) xs
rs = randomRs (1, n) g
n = length xs
main = do
g - getStdGen
let xs = randomElts g
Ok, that looks good, but what if I need some random values elsewhere
in the program? This doesn't return a new generator (and it can't
because you never get to the end of the list). Without using IO or ST,
you'd have to thread the parameter by hand or use the State monad,
right? This is where I
On Jul 31, 2007, at 16:20 , Chad Scherrer wrote:
calls. I suppose a State' monad, strict in the state, could help here.
You mean Control.Monad.State.Strict ?
--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats]
On 7/31/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote:
On Jul 31, 2007, at 16:20 , Chad Scherrer wrote:
calls. I suppose a State' monad, strict in the state, could help here.
You mean Control.Monad.State.Strict ?
Umm, yeah, I guess I do. Glad I hadn't started recoding it!
I'm trying to do something I thought would be pretty simple, but it's
giving me trouble.
Given a list, say [1,2,3], I'd like to be able to generate an infinite
list of random elements from that list, in this case maybe
[1,2,1,3,2,1,3,2,3,1,2,...]. I'm using IO for random purely due to
laziness
On Mon, Jul 30, 2007 at 02:40:35PM -0700, Chad Scherrer wrote:
I'm trying to do something I thought would be pretty simple, but it's
giving me trouble.
Given a list, say [1,2,3], I'd like to be able to generate an infinite
list of random elements from that list, in this case maybe
On 30/07/07, Chad Scherrer [EMAIL PROTECTED] wrote:
I'm trying to do something I thought would be pretty simple, but it's
giving me trouble.
Given a list, say [1,2,3], I'd like to be able to generate an infinite
list of random elements from that list, in this case maybe
On Mon, Jul 30, 2007 at 02:40:35PM -0700, Chad Scherrer wrote:
Given a list, say [1,2,3], I'd like to be able to generate an infinite
list of random elements from that list, in this case maybe
[1,2,1,3,2,1,3,2,3,1,2,...]. I'm using IO for random purely due to
laziness (my own, not Haskell's).
Why this obsession with IO? There should be no IO involved in this, except
for getting the initial generator.
Using IO just confuses what is going on.
-- Lennart
On 7/30/07, Cale Gibbard [EMAIL PROTECTED] wrote:
On 30/07/07, Chad Scherrer [EMAIL PROTECTED] wrote:
I'm trying to do
On 30/07/07, Lennart Augustsson [EMAIL PROTECTED] wrote:
Why this obsession with IO? There should be no IO involved in this, except
for getting the initial generator.
Using IO just confuses what is going on.
Indeed. Here's my version:
-- first define a shuffle function, completely pure!
Thanks for your responses.
Stefan, I appreciate your taking a step back for me (hard to judge
what level of understanding someone is coming from), but the example
you gave doesn't contradict my intuition either. I don't consider the
output [IO a] a list of tainted a's, but, as you suggest, a list
11 matches
Mail list logo