Re: State Transformer

Jorge Adriano
Anyway, I was coding some simple GA, and as you probably know I need to use random values. The most elegant way I could think of was to generate some
[...]
Monads! (right?)
Well, I suppose so. Generally speaking. But, you might want to consider using the standard random generation routines from the (IO) top level of your program, and just split the random generator for each function that uses it. IOW, passing each function its own random generator, instead of worrying about returning the "rest" of a global random sequence. (I don't have any good example code, I'm afraid, but at leat have a look at the chapter on Random in the library report on http://haskell.org) -kzm -- If I haven't seen further, it is by standing in the footprints of giants

[Obs: most answers I got end up in my pvt e-mail and not in the mailing list... I replyed in pvt to those. I do feel it some cases that is probably accidental as I do it all the time :), and the discussion ends leaving the mailing list. So i'd just like to let you know that I for one am in favour of having 'reply' to the mailing list as default :) ]
Monads! (right?)
Well, I suppose so. Generally speaking.
But, you might want to consider using the standard random generation routines from the (IO) top level of your program, and just split the random generator for each function that uses it. IOW, passing each function its own random generator, instead of worrying about returning the "rest" of a global random sequence.
(I don't have any good example code, I'm afraid, but at leat have a look at the chapter on Random in the library report on http://haskell.org)
-kzm
I did checked the Random library. My first idea was that, but I thought infinite lists of random numbers would be more elegant, anyway that is subjective. Both aproches suffer from the same problem, they reflect themselves on the type signatures. If I decide to try a deterministic approach to 'selection of individuals', signatures will change. The problem is more general, it's not just about the random numbers. If I want keep track of the best individuals, or the average fitness, or the evolution of some schemata... etc... I'll have to change the type signature. And this doesn't even changes the 'algorithm behaviour' in anyway...I'm just talking about keeping track of data. So my guess is that monads is the only elegant way out of this. J.A.
participants (2)
-
Jorge Adriano
-
Ketil Z Malde